asp.net - Getting data from child controls loaded programmatically -


2 control is created to manipulate a data object. To see 1 and another for editing

On a page I "Load" UserControl and pass data to it like this:

< Pre> ViewControl control = (ViewControl) LoadControl ("ViewControl.ascx"); Control.dataToView = Data Object; This.container.Controls.Add (control);

That's all right and inside control, I think the data can be captured and displayed.

Now I am trying to follow a similar approach for editing. I have a different user to control this for which I had to view the original data in the same way I did (with some boxes for editing):

  EditControl control = (EditControl LoadControl ("EditControl.ascx"); Control.dataToEdit = dataObject; This.container.Controls.Add (control);  

Whatever works fine.

The problem is now happening for this data when the user clicks a button, then I need to bring that data which was edited and used to do stuff with it, because what is happening The control programmic is being added, which means that the user has not been able to change the data anywhere.

Is this the solution? Or

Thank you. = "Text">

Simply put a reference to the control of the page as a variable in the code-variable of the page. I.e.

  Personal editing control control; Protected Zero Page_Init (Object Sender, EventArgs E) {Control = (EditControl) LoadControl ("EditControl.ascx"); Control.dataToEdit = dataObject; This.container.Controls.Add (control); } Secure Zero Button_Click (Object Sender, EventArgs e) {var Data toEdit = control.dataToEdit; }  

As long as you are making control in the right part of the life cycle of the page (start) then viewstate will be maintained. I'm assuming the data, just a textbox or something else?


Comments