dropdownlist losing data

Posted by Community Admin on 04-Aug-2018 16:33

dropdownlist losing data

All Replies

Posted by Community Admin on 02-Nov-2011 00:00

New to Sitefinity.  In reading through some older posts I see that ViewState at the page level was an issue for people with dynamically bound controls.  I am using 4.2 and set the check box to enable viewstate.  I bind a dropdownlist in the "if not ispostback", but am still losing my data on a button click.  Is this still an issue or am i missing something?

Posted by Community Admin on 07-Nov-2011 00:00

Hello Jeff,

The issue is resolved. Are you placing the checkbox in panel, updatepanel, or other? It would be best if you can post the code used for the dropdown so I can better advise you.

Greetings,
Stanislav Velikov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 07-Nov-2011 00:00

I have the dropdown inside of a panel, inside of a multiview, inside of an update panel.
Here is the stripped down code for what I am doing.


<
asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:MultiView ID="mv1" runat="server">
            <asp:View ID="vForm" runat="server">
                <asp:Panel ID="Panel1" runat="server">
                    <asp:DropDownList ID="ddlYear" runat="server" AppendDataBoundItems="true">
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                </asp:Panel>
            </asp:View>
        </asp:MultiView>
    </ContentTemplate>



Code Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
             ddlYear.Items.Add(New ListItem(Now.Year - 1, Now.Year - 1))
            ddlYear.Items.Add(New ListItem(Now.Year, Now.Year))
            ddlYear.Items.Add(New ListItem(Now.Year + 1, Now.Year + 1))
            ddlYear.Items.Add(New ListItem(Now.Year + 2, Now.Year + 2))
        End If
End Sub

</asp:UpdatePanel>

Posted by Community Admin on 10-Nov-2011 00:00

Hi Jeff,

Getting the control outside of the multi view preserved the changes to the dropdown. I made some modifications.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
 <ContentTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"
         oncheckedchanged="CheckBox1_CheckedChanged">
    </asp:CheckBox>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     <asp:Button ID="btnTest" runat="server" Text="Button" onclick="btnTest_Click" />
                   <asp:DropDownList ID="ddlYear" runat="server" AppendDataBoundItems="true">
                       <asp:ListItem></asp:ListItem>
                   </asp:DropDownList>
 </ContentTemplate>
 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="btnTest" />
 <asp:AsyncPostBackTrigger ControlID="CheckBox1" />
 </Triggers>
</asp:UpdatePanel>
code behind
public partial class WebUserControl1 : System.Web.UI.UserControl
    
        string _redirectURL = "~/SecondPage";
 
        public string RedirectURL
        
            get return _redirectURL;
            set _redirectURL = value;
        
 
        protected void Page_Load(object sender, EventArgs e)
        
            if (!IsPostBack)
            
                ddlYear.Items.Add(new ListItem("item1"));
                ddlYear.Items.Add(new ListItem("item2"));
                ddlYear.Items.Add(new ListItem("item3"));
                ddlYear.Items.Add(new ListItem("item4"));
                ddlYear.Items.Add(new ListItem("item5"));
            
        
 
        protected void btnTest_Click(object sender, EventArgs e)
        
            Response.Redirect(RedirectURL);
        
 
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        
            this.TextBox1.Text = this.CheckBox1.Checked ? "true" : "false";
        
    


Best wishes,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed