UpdatePanel GridView DropDownList AutoPostBack Problem

Last post 05-15-2007 1:01 PM by susanh. 12 replies.

Sort Posts:

  • UpdatePanel GridView DropDownList AutoPostBack Problem

    04-26-2007, 12:11 PM
    • Loading...
    • mxmissile
    • Joined on 06-19-2002, 10:42 AM
    • Ewtahh
    • Posts 347

    I have a DropDownList inside a TemplateColumn inside a GridView inside a UpdatePanel. (out of breath saying that)

    I have the DDL's AutoPostBack set to true and the OnSelectedIndexChanged event set to an event in my code.  The problem is when the DDL's index changes, it posts back.  It does not do the UpdatePanel magic and not post the whole page back, and the OnSelectedIndexChanged event does not fire.  Anyone see anything wrong with my approach?

    <asp:TemplateField HeaderText="Priority">
      <ItemTemplate>
        <asp:DropDownList ID="PriorityList" runat="server" 
         AutoPostBack="true" OnSelectedIndexChanged="PriorityList_SelectedIndexChanged" />
      </ItemTemplate>
    </asp:TemplateField>
      
    protected void PriorityList_SelectedIndexChanged(object sender, EventArgs e)
    {
      MessageLabel.Text = "prio";
    }
     
    http://www.heliosfx.com
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    04-26-2007, 11:37 PM
    Have you set property EnablePartialRendering="true" of ScriptManager ?
    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    04-26-2007, 11:40 PM

    Check the property of UpdatePanel UpdateMode="Conditional"

    whether it is being set or not ?

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    04-26-2007, 11:53 PM

    or may be GridView is not compatable with UpdatPanel thats why you fave this problem..

    check this url http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    04-27-2007, 10:04 AM
    • Loading...
    • mxmissile
    • Joined on 06-19-2002, 10:42 AM
    • Ewtahh
    • Posts 347
    This all might be a false alarm, does Page_Load get called when an UpdatePanel does its update thing?
    http://www.heliosfx.com
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    04-27-2007, 11:24 PM
    Asynchronous PostBack occurs
    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-11-2007, 5:57 PM
    • Loading...
    • susanh
    • Joined on 10-05-2006, 5:09 PM
    • Posts 15

    Has anyone found a solution to this?  I seem to be having the same problem.  I have DropDownLists in a column of a GridView within an UpdatePanel, like so:

    <asp:TemplateField HeaderText="Group Number" >
        <itemtemplate>
            <asp:DropDownList id="ddlGroupNumber" runat="server" AutoPostBack="true"
                OnSelectedIndexChanged="ddlGroupNumber_SelectedIndexChanged">
            </asp:DropDownList>
        </itemtemplate>
        <itemstyle cssclass="centerData"/>
    </asp:TemplateField>

    The UpdatePanel's UpdateMode="Conditional" and the ScriptManager's EnablePartialRendering="true".

    Before adding the above column, AJAX and this GridView worked perfectly.  A button in another column could be clicked and only its state changed; the whole page didn't get repainted.  After adding this column, selecting a new value in a dropdown (or clicking that button in another column) causes a full postback.  Even removing the event and the autopostback properties didn't help.

    I'm stuck!  Can anyone offer any suggestions? 

     

  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-11-2007, 7:23 PM
    • Loading...
    • WishStar99
    • Joined on 08-05-2006, 12:11 AM
    • VietNam
    • Posts 549

    hmm i wonder why ............ i will try figure it out, but here's

    a work around: add a hidden button inside your updatepanel but outside the gridview;

    <asp:button id="btnIndexChanged" Text="Index Changed" style="display: none;" OnClick="ddlGroupNumber_SelectedIndexChanged" runat="server" />

    Add a javascript function to your page:

    function IndexChanged()
    { document.getElementById('" + this.btnIndexChanged.ClientID + "').click(); }

    Add this functio protocol to your DropDownList

    <asp:DropDownList ID="ddlGroupNumber" onchange="IndexChanged();" runat="server">

    That's all to it ...  see it yourself --> http://forums.advancemicrotech.com/threads/thread051107.aspx

    Aeries' Coders
    Programmers' Forums at Advance Microtech


    Nothing is impossible when it comes to coding.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-11-2007, 11:42 PM

    Thanks, working perfectly Smile

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-14-2007, 11:20 AM
    • Loading...
    • susanh
    • Joined on 10-05-2006, 5:09 PM
    • Posts 15

    I must be missing something.  I'm trying your code as above, but I get this JavaScript error "document.getElementById(...) is null or not an object."  I added this alert as the first line of the javascript function "alert("button name: " + this.btnIndexChanged);" and I get a messagebox saying "button name: undefined."

    The next problem is that ddlGroupNumber_SelectedIndexChanged(object sender, EventArgs e) in the code behind page needs to have the sender object so I can do this...

                DropDownList groupList = sender as DropDownList;
                GridViewRow row = (GridViewRow)groupList.NamingContainer;

     ...and work with the data associated with the row that was touched.  Can I do that in Javascript?

     Thank you so much for your help!


     

     

     

  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-14-2007, 1:46 PM
    • Loading...
    • WishStar99
    • Joined on 08-05-2006, 12:11 AM
    • VietNam
    • Posts 549

    post your html & code behind here or you can email me your .aspx and .cs files and i'll check it out for you.

    my email: coders@advancemicrotech.com

    Aeries' Coders
    Programmers' Forums at Advance Microtech


    Nothing is impossible when it comes to coding.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-15-2007, 12:34 AM

    Getting an error like "document.getElementById(...) is null or not an object."  means

    that control is not found , you are getting an error "button name: undefined." means same, control ID is not found

    Post your code so, it will help to resolve the problem.

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdatePanel GridView DropDownList AutoPostBack Problem

    05-15-2007, 1:01 PM
    • Loading...
    • susanh
    • Joined on 10-05-2006, 5:09 PM
    • Posts 15

    I've given up on getting the DropDownList to work.  I tried a simple ListBox with the same result.  The mere presence of these controls causes any changes in the grid to produce a full postback and repaint.  I've switched to using a RadioButtonList since I only have to display 0, 1, 2 as choices.  So what I have on the page is:

    <asp:TemplateField HeaderText="Execution Group">
        <itemstyle cssclass="centerAll"/>   
        <itemtemplate>
            <asp:RadioButtonList id="radGroupNum" runat="server" RepeatDirection="Horizontal"
            OnSelectedIndexChanged="radGroupNum_SelectedIndexChanged" AutoPostBack="true" >
            </asp:RadioButtonList>
        </itemtemplate>
    </asp:TemplateField>

    On the code behind there is method to handle the RowDataBound event which does this to populate the lists and pick the right selection for each row:

                RadioButtonList list = args.Row.FindControl("radGroupNum") as RadioButtonList;
                    if (list != null)
                    {
                        foreach (ExecutionGroup group in executionGroups)
                        {
                            list.Items.Add(new ListItem(group.GroupNumber.ToString()));
                        }
                        list.DataBind();
                        list.SelectedValue = ((BusinessActionInfo)args.Row.DataItem).ExecutionGroupNumber.ToString();
                    }

    and finally...

            protected void radGroupNum_SelectedIndexChanged(object sender, EventArgs e)
            {
                RadioButtonList groupList = sender as RadioButtonList;
                GridViewRow row = (GridViewRow)groupList.NamingContainer;
                BusinessActionInfo baInfo = (BusinessActionInfo)grdBusinessActions.Data[row.RowIndex];
                baInfo.ExecutionGroupNumber = short.Parse(groupList.SelectedValue);
                consoleService.UpdateBusinessActionInfoGroupNumber(baInfo);
            }

    I'm posting all this in case it helps anyone else. 

Page 1 of 1 (13 items)
Microsoft Communities