Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have done this in the past. I have not had to do this since the days of .NET 1.1, but the principal removes the same.</p> <p>I did it on Page_Load not Init have to reload the controls that you created on the last page cycle.</p> <p>First you need to keep track of the controls you have created on each page cycle. This includes type, name etc. . .</p> <p>Then on each page load you need to rebuild them.</p> <p>You do that by re-creating the control, assinging it the exact same id, add it to the sampe place on the page and finally in the ViewState["LoadedControl"] to the control type.</p> <p>Here is the code I used, I only did this with User Controls that I created. I have not tried this with an ASP.NET control, but I think it would work the same.</p> <p>In this case I have an ArrayList of Triplets (keep in mind this is .NET 1.1) adn the first item was a PageView ID. You might not need that for your application.</p> <pre><code>protected void Page_Load(object sender, System.EventArgs e) { //********************************************************** //* dynCtlArray will hold a triplet with the PageViewID, * //* ControlID, and the Control Name * //********************************************************** ArrayList dynCtlArray = (ArrayList)this.ViewState["dynCtlArray"]; if (dynCtlArray != null) { foreach (object obj in dynCtlArray) { Triplet ctrlInfo = (Triplet)obj; DynamicLoadControl(ctrlInfo); } } } private void DynamicLoadControl(Triplet ctrlInfo) { // ERROR HANDLING REMOVED FOR ANSWER BECAUSE IT IS NOT IMPORTANT YOU SHOULD HANDLE ERRORS IN THIS METHOD Control ctrl = this.LoadControl(Request.ApplicationPath + "/UC/" + (string)ctrlInfo.Third); ctrl.ID = (string)ctrlInfo.Second; // Create New PageView Item Telerik.WebControls.PageView pvItem = this.RadMultiPage1.PageViews[(int)ctrlInfo.First]; pvItem.Controls.Add(ctrl); /****************************************************** * The ControlName must be preserved to track the * * currently loaded control * * ****************************************************/ ViewState["LoadedControl"] = (string)ctrlInfo.Third; } private void RegisterDynControl(Triplet trip) { ArrayList dynCtlArray = (ArrayList)this.ViewState["dynCtlArray"]; if (dynCtlArray == null) { dynCtlArray = new ArrayList(); this.ViewState.Add("dynCtlArray", dynCtlArray); } dynCtlArray.Add(trip); } </code></pre> <p>In some method on your page</p> <pre><code>// Create new Control Control ctrl = Page.LoadControl("../UC/MyUserControl.ascx"); // . . . snip .. . // Create Triplet Triplet ctrlInfo = new Triplet(0, ctrl.ID, "MyUserControl.ascx"); // RegisterDynControl to ViewState RegisterDynControl(ctrlInfo); // . . . snip .. . </code></pre> <p>To access the controls to save there information you will have to do a <code>this.Page.FindControl('');</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload