Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A different way of LoadControl which works (only .NET 4 tested)</p> <p>Usage is as follows in any page you can call</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { Control ctrl = SomeClass.GetNewUserControl( "hello add me"); Panel1.Controls.Add(ctrl); } </code></pre> <p><strong>~/app_code/BaseMyControls.cs:</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Web; /// &lt;summary&gt; /// Summary description for BaseMyControls /// &lt;/summary&gt; public class BaseMyControls : System.Web.UI.UserControl { public string strProperty; public BaseMyControls() { } } </code></pre> <p><strong>~/app_code/SomeClassInApp_Code.cs:</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Web; /// &lt;summary&gt; /// Summary description for SomeClassInApp_Code /// &lt;/summary&gt; public class SomeClassInApp_Code { public static System.Web.UI.Control GetNewUserControl(string someString) { BaseMyControls bc = (BaseMyControls)(new System.Web.UI.UserControl()).LoadControl("~/controls/MyUC.ascx"); bc.strProperty = someString; return bc; } } </code></pre> <p><strong>~/controls/MyUC.aspx:</strong></p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyUC.ascx.cs" Inherits="MyUC" %&gt; &lt;asp:Label runat="server" ID="lbl" /&gt;&lt;/asp:Label&gt; </code></pre> <p><strong>~/controls/MyUC.aspx.cs:</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class MyUC : BaseMyControls { protected void Page_Load(object sender, EventArgs e) { string a = this.strProperty; lbl.Text = a; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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