1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / AutoPostBack returns same value on index changed?

AutoPostBack returns same value on index changed?

2 posts, 0 answered
  1. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    03 Jul 2009
    Link to this post
    Hi there, I have a RadComboBox and a regular asp drop down list (for testing) on my page and I have enabled autopostback on tehm. Whenever I change the item in either control, it changes back to the first item in the control.

    Here is my designer code:

    <div id="latest-post" class="post"
        <telerik:RadComboBox ID="fyi_combobox" runat="server" ShowDropDownOnTextboxClick="true" AutoPostBack="true" /><br /> 
        <asp:Literal ID="test" runat="server" text="default" /><br /><br /> 
        <asp:DropDownList ID="fyi_dropdownlist" runat="server" AutoPostBack="true" /><br /> 
        <asp:Literal ID="test2" runat="server" Text="default2" /> 
    </div> 
     

    and here is the code-behind:

     private void GetStates() 
        { 
            var db = new GSFyi.GSFyiDataClassesDataContext(); 
     
            var states = (from s in db.FYI_States select s); 
     
            fyi_combobox.DataSource = states; 
            fyi_combobox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(fyi_combobox_SelectedIndexChanged); 
            fyi_combobox.DataTextField = "name"
            fyi_combobox.DataValueField = "id"
            fyi_combobox.DataBind(); 
     
            fyi_dropdownlist.DataSource = states; 
            fyi_dropdownlist.SelectedIndexChanged += new EventHandler(fyi_dropdownlist_SelectedIndexChanged); 
            fyi_dropdownlist.DataTextField = "name"
            fyi_dropdownlist.DataValueField = "id"
            fyi_dropdownlist.DataBind(); 
                 
     
        } 

    I thought at first it was just the Rad control and I might be missing some code or something, but the standard ASP control is doing it too.

    Thanks guys,
    anders
  2. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    03 Jul 2009
    Link to this post
    Once again, I solved my own (stupidity) problem :P

    Issue was I was calling GetStates() whenever the page loaded, so even on the postbacks it was rebinding the dropdown. All I had to do was add if(!IsPostBack) to my page_load.

    Regards,
    anders
2 posts, 0 answered