Note that there are some explanatory texts on larger screens.

plurals
  1. POExtending usercontrol, Inner controls not initialized if declared on ascx page
    primarykey
    data
    text
    <p>The Usercontrol I am creating is made up of 3 files as expected (ascx, ascx.cs, and ascx.designer.cs)</p> <p>My Problem :</p> <p>Controls created in the aspx page ( asp:Button runat="server" id="mybutton" />) are not being initialized properly, such that attaching to the 'Load' event, and trying to use button, results in a null object exception</p> <p>I suspect this is a Visual Studio problem, either weird bug or unusal setting, but it wouldn't surprise me if I'm doing something silly.</p> <p>My attempted work-a-arounds</p> <ol> <li><p>I've copied another working User control from a different project into this project in visual studio and it too does not work (controls defined in ascx page are null in load event in code behind page, though they work fine where I copied them from)</p></li> <li><p>I'm using the 'CreateChildControls()' method, as I've done in some other composite controls, but then everything is still null in the load and init events</p></li> <li><p>I've created a seperate solution and project file, and added all the files and references, but still, this does not help the situation.</p></li> </ol> <p>It appears to me that the 'page life cycle' (control life cycle?) is not initializing the controls properly for some reason, but cant see why, please someone help.</p> <p>Posting my code as request :</p> <pre><code>PersonalDetails.aspx &lt;cwpEditControl:PersonalDetails runat="server" id="edtPersonalDetails" /&gt; PersonalDetails.ascx &lt;%@ Control Language="C#" CodeBehind="PersonalDetails.ascx.cs" Inherits="company.web.CustomerWebPortal.controls.edit.PersonalDetails" %&gt; &lt;asp:Button runat="server" ID="myTestButton" /&gt; PersonalDetails.ascx.cs public PersonalDetails() { this.Load += new EventHandler(PersonalDetails_Load); } void PersonalDetails_Load(object sender, EventArgs e) { this.myTestButton.Text = "Submit"; //this line creates an exception! } PersonalDetails.ascx.designer.cs protected global::System.Web.UI.WebControls.Button myTestButton; </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.
 

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