|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamic checkbox loses checked stateFurther to my earlier post - I have created a very simple test app which demonstrates this problem. Any advice gratefully accepted ;-). In a simple website (I am using .Net V2.0.50727.42) add the following to the default.aspx page : <asp:CheckBox ID="CheckBox1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <hr /> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> <hr /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> Now in Page_Load add : Label1.Text = CheckBox1.Checked.ToString(); CheckBox ck = new CheckBox(); ck.Checked = CheckBox1.Checked; PlaceHolder1.Controls.Add(ck); So - the question is WHY does the dynamic checkbox not get checked ???. Pressing the button should transfer the CheckBox1 checked status to the dynamic control ???. The label is just for confirmation. Thanks Graham Hi Graham,
To understand the page lifecycle's tidbit that you ran into; move the following 2 lines from the page_load to the page_init and see what happens: CheckBox ck = new CheckBox(); PlaceHolder1.Controls.Add(ck); After doing that look at this demo to experience another effect of creating controls dynamically: http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx Then search this newsgroup for previous threads in which we discussed the page lifecycle and dynamically created controls. Show quoteHide quote "Oxns" wrote: > Hi, > > Further to my earlier post - I have created a very simple test app which > demonstrates this problem. Any advice gratefully accepted ;-). > > In a simple website (I am using .Net V2.0.50727.42) add the following to the > default.aspx page : > > <asp:CheckBox ID="CheckBox1" runat="server" /> > > <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> > > <hr /> > > <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> > > <hr /> > > <asp:Button ID="Button1" runat="server" Text="Button" > OnClick="Button1_Click" /> > > > > Now in Page_Load add : > > Label1.Text = CheckBox1.Checked.ToString(); > > CheckBox ck = new CheckBox(); > > ck.Checked = CheckBox1.Checked; > > PlaceHolder1.Controls.Add(ck); > > > > So - the question is WHY does the dynamic checkbox not get checked ???. > > Pressing the button should transfer the CheckBox1 checked status to the > dynamic control ???. The label is just for confirmation. > > Thanks > > Graham > > > > > Philip,
Many thanks for the excellent response :-)). Made the change suggested but made ck globally available so that I could also change it in Page_Load and its fine :-)). Started to review the other stuff but not finished yet. The 'annoying factor' is that almost everything else works as expected with the code in Page_Load :-O, textboxes, labels, dropdowns etc. :-O. Many Thanks Regards Graham Show quoteHide quote "Phillip Williams" <WEBSWAPP@newsgroups.nospam> wrote in message news:128BCE5D-3EC5-4430-9CFC-3574BD5C27B1@microsoft.com... > Hi Graham, > > To understand the page lifecycle's tidbit that you ran into; move the > following 2 lines from the page_load to the page_init and see what > happens: > > CheckBox ck = new CheckBox(); > PlaceHolder1.Controls.Add(ck); > > After doing that look at this demo to experience another effect of > creating > controls dynamically: > http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx > > Then search this newsgroup for previous threads in which we discussed the > page lifecycle and dynamically created controls. > > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Oxns" wrote: > >> Hi, >> >> Further to my earlier post - I have created a very simple test app which >> demonstrates this problem. Any advice gratefully accepted ;-). >> >> In a simple website (I am using .Net V2.0.50727.42) add the following to >> the >> default.aspx page : >> >> <asp:CheckBox ID="CheckBox1" runat="server" /> >> >> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> >> >> <hr /> >> >> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> >> >> <hr /> >> >> <asp:Button ID="Button1" runat="server" Text="Button" >> OnClick="Button1_Click" /> >> >> >> >> Now in Page_Load add : >> >> Label1.Text = CheckBox1.Checked.ToString(); >> >> CheckBox ck = new CheckBox(); >> >> ck.Checked = CheckBox1.Checked; >> >> PlaceHolder1.Controls.Add(ck); >> >> >> >> So - the question is WHY does the dynamic checkbox not get checked ???. >> >> Pressing the button should transfer the CheckBox1 checked status to the >> dynamic control ???. The label is just for confirmation. >> >> Thanks >> >> Graham >> >> >> >> >> You are welcome, Graham.
Show quoteHide quote "Oxns" wrote: > Philip, > > Many thanks for the excellent response :-)). Made the change suggested but > made ck globally available so that I could also change it in Page_Load and > its fine :-)). > > Started to review the other stuff but not finished yet. > > The 'annoying factor' is that almost everything else works as expected with > the code in Page_Load :-O, textboxes, labels, dropdowns etc. :-O. > > Many Thanks > > Regards > > Graham > > "Phillip Williams" <WEBSWAPP@newsgroups.nospam> wrote in message > news:128BCE5D-3EC5-4430-9CFC-3574BD5C27B1@microsoft.com... > > Hi Graham, > > > > To understand the page lifecycle's tidbit that you ran into; move the > > following 2 lines from the page_load to the page_init and see what > > happens: > > > > CheckBox ck = new CheckBox(); > > PlaceHolder1.Controls.Add(ck); > > > > After doing that look at this demo to experience another effect of > > creating > > controls dynamically: > > http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx > > > > Then search this newsgroup for previous threads in which we discussed the > > page lifecycle and dynamically created controls. > > > > -- > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Oxns" wrote: > > > >> Hi, > >> > >> Further to my earlier post - I have created a very simple test app which > >> demonstrates this problem. Any advice gratefully accepted ;-). > >> > >> In a simple website (I am using .Net V2.0.50727.42) add the following to > >> the > >> default.aspx page : > >> > >> <asp:CheckBox ID="CheckBox1" runat="server" /> > >> > >> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> > >> > >> <hr /> > >> > >> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> > >> > >> <hr /> > >> > >> <asp:Button ID="Button1" runat="server" Text="Button" > >> OnClick="Button1_Click" /> > >> > >> > >> > >> Now in Page_Load add : > >> > >> Label1.Text = CheckBox1.Checked.ToString(); > >> > >> CheckBox ck = new CheckBox(); > >> > >> ck.Checked = CheckBox1.Checked; > >> > >> PlaceHolder1.Controls.Add(ck); > >> > >> > >> > >> So - the question is WHY does the dynamic checkbox not get checked ???. > >> > >> Pressing the button should transfer the CheckBox1 checked status to the > >> dynamic control ???. The label is just for confirmation. > >> > >> Thanks > >> > >> Graham > >> > >> > >> > >> > >> > > >
radiobuttonlist.selectedIndex always -1.........
Checkbox in datagrid.... How to read value of a dynamically created radiobuttonlist control? DataGrid Functionality Questions Checkbox state after postback cancel toolbar buttonclick from client-side javascript asp.net control to run in web page like just COM asp:Repeater + no viewstate + DataBind() ?? Where are the events of the aspx? Looking for graphic control to use in .NET |
|||||||||||||||||||||||