I am dynamically adding in some controls onto an empty the panel (a checkbox, image, and textbox) using a foreach. Which works fine. When i change the text or check the checkbox and submit, on postback the panel doesnt have any controls in it!
I've ensured that nothing is happening in the page_init - it is before this funciton that the panel is reset.
Does anyone have any ideas as to how i could put the panel into a session before the postback?
I now understand why they arent being persisted and i am able to get the values of the textboxes and the checkboxes that have been checked.
Now i need to store the values in the database. What i was originally thinking of doing what looping over the controls in the panel. What the panel
should have in it is a number of rows, each row a checkbox, an image, and a text box. So the three controls are attributes of a sponsor.
The problem that i have now is that i am always getting the textbox, but only getting the checked checkboxes. I am having to loop over the controls, find a textbox, find its id (i appended the sponsor id to the end of the id of each checkbox and textbox
so i know which sponsor they are from), then see if there is a checkbox with this id <- not sure how to do this yet either..
This seems a bit conveluted. Any one with any better ideas?
dscanlan81
Member
1 Points
4 Posts
Panel Controls disappear after postback
Jun 19, 2009 03:39 PM|LINK
Hi,
I am dynamically adding in some controls onto an empty the panel (a checkbox, image, and textbox) using a foreach. Which works fine. When i change the text or check the checkbox and submit, on postback the panel doesnt have any controls in it!
I've ensured that nothing is happening in the page_init - it is before this funciton that the panel is reset.
Does anyone have any ideas as to how i could put the panel into a session before the postback?
Evan Freeman
Contributor
2353 Points
515 Posts
Re: Panel Controls disappear after postback
Jun 19, 2009 03:54 PM|LINK
Check out this post it should answer everything,
http://forums.asp.net/t/1383111.aspx
Codeundrum: Code that puzzles.
sumitd
Star
12168 Points
2151 Posts
Re: Panel Controls disappear after postback
Jun 19, 2009 05:12 PM|LINK
Refer below article:
http://www.4guysfromrolla.com/articles/092904-1.aspx
Visit: www.msblogdirectory.com
www.dotnetspeaks.com
srinivaskotr...
Star
11228 Points
1792 Posts
Re: Panel Controls disappear after postback
Jun 19, 2009 06:47 PM|LINK
hi,
no need to put panel in session. write your add controls code in in not post back
ex:
page_load
if not ispostback then
write our controls adding code
endif
Srinivas Kotra.
venkatu2005
All-Star
32487 Points
6742 Posts
Re: Panel Controls disappear after postback
Jun 20, 2009 06:51 AM|LINK
Check this
http://www.aspsnippets.com/post/2009/06/13/Creating-Dynamic-TextBox-Controls-in-ASPNet.aspx
Thanks.
dscanlan81
Member
1 Points
4 Posts
Re: Panel Controls disappear after postback
Jun 23, 2009 09:57 AM|LINK
Thanks for the replies.
I now understand why they arent being persisted and i am able to get the values of the textboxes and the checkboxes that have been checked.
Now i need to store the values in the database. What i was originally thinking of doing what looping over the controls in the panel. What the panel should have in it is a number of rows, each row a checkbox, an image, and a text box. So the three controls are attributes of a sponsor.
The problem that i have now is that i am always getting the textbox, but only getting the checked checkboxes. I am having to loop over the controls, find a textbox, find its id (i appended the sponsor id to the end of the id of each checkbox and textbox so i know which sponsor they are from), then see if there is a checkbox with this id <- not sure how to do this yet either..
This seems a bit conveluted. Any one with any better ideas?
dscanlan81
Member
1 Points
4 Posts
Re: Panel Controls disappear after postback
Jun 23, 2009 10:23 AM|LINK
for anyone that stumbles on this thread. I managed to find the control by using:
try{
CheckBox
c = (CheckBox)pl1.FindControl("chk" + id.ToString());}catch{}
if this throws an error then its safe to assume that its wasnt checked. I find the controls that were passed over using:
string
[] ctrls = Request.Form.ToString().Split('&');