how to handle multiple dynamic controls after postback?
-
Here is my requirement : users has to able to create their custom forms through web interface. it should more or less equal to visual studio 2005 deisgner. I come across many articles and done some work around to create a drag and drop scenario in web application for controls but i finally ended with nothing. Again i changed layout for that maodule :Form Designer: i came up with linear design which is having a property window on right side holding few common properties for most controls like Control name, control type, height, width etc. I have another layout having multiple rows & 2 columns(like Left & Right), in each cell i assigned a link button. Here how i planned to work it out: When user click on any cell, right side properties will be visible to user and user can select the controls of his/her choice setting some properties to it. Upon clicking save button (which will be located in the property window) program will generate a control at the link button place. Problems am facing : I could not able to regenerate the controls after postback done. I could able to save & load control properties from array but could not able to establish the same controls after postback done. can anyone give me references or suggesstions :((how to handle multiple dynamic controls after postback? from: krishna
-
Here is my requirement : users has to able to create their custom forms through web interface. it should more or less equal to visual studio 2005 deisgner. I come across many articles and done some work around to create a drag and drop scenario in web application for controls but i finally ended with nothing. Again i changed layout for that maodule :Form Designer: i came up with linear design which is having a property window on right side holding few common properties for most controls like Control name, control type, height, width etc. I have another layout having multiple rows & 2 columns(like Left & Right), in each cell i assigned a link button. Here how i planned to work it out: When user click on any cell, right side properties will be visible to user and user can select the controls of his/her choice setting some properties to it. Upon clicking save button (which will be located in the property window) program will generate a control at the link button place. Problems am facing : I could not able to regenerate the controls after postback done. I could able to save & load control properties from array but could not able to establish the same controls after postback done. can anyone give me references or suggesstions :((how to handle multiple dynamic controls after postback? from: krishna
Some general advice for working with dynamic controls
- Always assign dynamic controls and all of their naming containers explicit ids.
- Always recreate your dynamic controls in either the page's
OnInit
method orInit
event handler. - Ensure that you assign the same id to your controls and all of their naming containers on initial creation and at each postback. Assign the ids at the time you recreate your controls.[
OnInit
method or inInit
event handler] - Ensure that you place the controls in the same naming containers on the page on initial creation and at each postback. Site the controls at the time you create them.[
OnInit
method or inInit
event handler]
The ASP.NET page model is going to use a combination of
UniqueId
,ClientId
, and positional association within the control tree in order to restore your control's ViewState, match up post data, and raise postback events. In order to make sure that your controls are created properly for that processing to happen, your best bet is always to preform the actions in the page'sOnInit
method orInit
event handler, as I've beaten to death above. :) I'd suggest that you take a peek at the Lifecycle of a Page[^]. Even though that article was written for .NET 1.0, it is still accurate for versions 2.0 and 3.0. It may also prove helpful for you to download a copy of Lutz Roeder's Reflector[^] and look over the implementation of thePage
class. Hope that helps. :)--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
-
Some general advice for working with dynamic controls
- Always assign dynamic controls and all of their naming containers explicit ids.
- Always recreate your dynamic controls in either the page's
OnInit
method orInit
event handler. - Ensure that you assign the same id to your controls and all of their naming containers on initial creation and at each postback. Assign the ids at the time you recreate your controls.[
OnInit
method or inInit
event handler] - Ensure that you place the controls in the same naming containers on the page on initial creation and at each postback. Site the controls at the time you create them.[
OnInit
method or inInit
event handler]
The ASP.NET page model is going to use a combination of
UniqueId
,ClientId
, and positional association within the control tree in order to restore your control's ViewState, match up post data, and raise postback events. In order to make sure that your controls are created properly for that processing to happen, your best bet is always to preform the actions in the page'sOnInit
method orInit
event handler, as I've beaten to death above. :) I'd suggest that you take a peek at the Lifecycle of a Page[^]. Even though that article was written for .NET 1.0, it is still accurate for versions 2.0 and 3.0. It may also prove helpful for you to download a copy of Lutz Roeder's Reflector[^] and look over the implementation of thePage
class. Hope that helps. :)--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
Hi jesse, Thanks for your valuable suggestion. I am doing the same steps and also following robbieMorris sample at > http://www.eggheadcafe.com/articles/extendtextboxviewstate.asp , here he clearly demonstrated creating controls runtime as well as handling them at postback & in viewstate. In my scenario i took two rows and two columns. > I have linkbuttons in each cell > upon clikcing on linkbutton a window will be enabled at right side (assume it as property window) > From that window user will select controls from a dropdown list (like text box, label etc), enter name, height, width for that controls (as we do in property window). > upon hitting on save button in that property window, my program will create a runtime control. > next he'll click linkbutton in another cell and follow same procedure for creating controls. > but at this point am facing problem though am following Robbie Morris concepts i dont know control is not creating as well as i am loosing last control which i created. appreciate ypur help on this !!! From, Krishna
-
Hi jesse, Thanks for your valuable suggestion. I am doing the same steps and also following robbieMorris sample at > http://www.eggheadcafe.com/articles/extendtextboxviewstate.asp , here he clearly demonstrated creating controls runtime as well as handling them at postback & in viewstate. In my scenario i took two rows and two columns. > I have linkbuttons in each cell > upon clikcing on linkbutton a window will be enabled at right side (assume it as property window) > From that window user will select controls from a dropdown list (like text box, label etc), enter name, height, width for that controls (as we do in property window). > upon hitting on save button in that property window, my program will create a runtime control. > next he'll click linkbutton in another cell and follow same procedure for creating controls. > but at this point am facing problem though am following Robbie Morris concepts i dont know control is not creating as well as i am loosing last control which i created. appreciate ypur help on this !!! From, Krishna
If you are following the advice that I posted and the approach that Robbe uses in his tutorial, then I don't see anything in your description that would indicate a design issue. At this point, without looking at some of the code, I don't think that we will be able to help you further. I'd suggest that we start by looking at the relevant snipits where you recreate the controls on postback / Save button click.
--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi