Redrawing dynamically added controls
-
I have created an aspx form where most of the controls are added dynamically. If I redraw the form with the same set of control, the dynamic controls do not seem to be redrawn with the new values. For example, I have checkbox that was checked. I select my button to reset it. Stepping through the code, I see the checkbox checked property is set to false. The form comes back up as if nothing has been altered. The checkbox is still checked. Has anyone else run into this problem with ASP.NET? If so, how did you resolve this issue?
-
I have created an aspx form where most of the controls are added dynamically. If I redraw the form with the same set of control, the dynamic controls do not seem to be redrawn with the new values. For example, I have checkbox that was checked. I select my button to reset it. Stepping through the code, I see the checkbox checked property is set to false. The form comes back up as if nothing has been altered. The checkbox is still checked. Has anyone else run into this problem with ASP.NET? If so, how did you resolve this issue?
Are all of your controls tagged with runat="server" within the tag? Your subroutine written in VB running on the server to reset the values will only work on controls that have that prefix. Also make sure you wrap your controls within a form tag.
.... ... HTH Nick Parker
-
Are all of your controls tagged with runat="server" within the tag? Your subroutine written in VB running on the server to reset the values will only work on controls that have that prefix. Also make sure you wrap your controls within a form tag.
.... ... HTH Nick Parker
Here is a snippet of my VB code that adds a dropdown listbox to my form dynamically. How do I set the controls in my VB code to force it to runat server? Dim tmpDDLB As System.Web.UI.WebControls.DropDownList Dim lstitem As ListItem lstitem = New ListItem("A", "0") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "1") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "2") tmpDDLB.Items.Add(lstitem) tmpDDLB.SelectedIndex = 0 MyForm.Controls.Add(tmpDDLB)
-
Here is a snippet of my VB code that adds a dropdown listbox to my form dynamically. How do I set the controls in my VB code to force it to runat server? Dim tmpDDLB As System.Web.UI.WebControls.DropDownList Dim lstitem As ListItem lstitem = New ListItem("A", "0") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "1") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "2") tmpDDLB.Items.Add(lstitem) tmpDDLB.SelectedIndex = 0 MyForm.Controls.Add(tmpDDLB)
Your controls are runat=server, they are certainly not being created on the client. Make sure you are persisting the value you want to change. Remember when the page reloads it is redrawing the controls as if for the first time.
-
Here is a snippet of my VB code that adds a dropdown listbox to my form dynamically. How do I set the controls in my VB code to force it to runat server? Dim tmpDDLB As System.Web.UI.WebControls.DropDownList Dim lstitem As ListItem lstitem = New ListItem("A", "0") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "1") tmpDDLB.Items.Add(lstitem) lstitem = New ListItem("C", "2") tmpDDLB.Items.Add(lstitem) tmpDDLB.SelectedIndex = 0 MyForm.Controls.Add(tmpDDLB)
If this code is in your Init event make sure your checking for Page.IsPostBack otherwise your controls get re-created and initialized on every PostBack.
-
If this code is in your Init event make sure your checking for Page.IsPostBack otherwise your controls get re-created and initialized on every PostBack.
I do check to postback and the controls are redrawn with the new values. However, the UI displays them as if no change has occurred. I can even step through my code, see the values being reset, and the UI will not reflect the change. Any other suggestions?