dropdownlist losing data
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?
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
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>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>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";