Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have tried the following code as well - which yields the same result (i.e. both lblTitle and lblDescription are null)</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { if (_ErrorMessage != null) { lblTitle.Text = _ErrorMessage.Message; lblDescription.Text = _ErrorMessage.Description; } } </code></pre> <p>I had the understanding that the LoadControl function brought the control it is loading up to the current 'state' of the page onto which it is being included on. hence the Init, Page_Load etc are all run as part of the LoadControl call.</p> <p>Interestingly this (unanswered) asp.net forums post exhibits the same problem as I am experiencing.</p> <p><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2333625&amp;SiteID=1" rel="noreferrer">MSDN Forums Post</a></p> <p>Additionally - From the MSDN:</p> <blockquote> <p>When you load a control into a container control, the container raises all of the added control's events until it has caught up to the current event. However, the added control does not catch up with postback data processing. For an added control to participate in postback data processing, including validation, the control must be added in the Init event rather than in the Load event. </p> </blockquote> <p>Therefore shouldn't LoadControl correctly initalise the control?</p> <p><strong>EDIT:</strong></p> <p>Ok, so I'm answering my own question here ..</p> <p>I found an answered version of the forum post I linked to above <a href="http://forums.asp.net/t/1174838.aspx" rel="noreferrer">Here</a> </p> <p>Essentially the answer is that the <code>LoadControl( type, params )</code> cannot infer the 'page infront' ascx to parse and hence it doesn't bother initalising any of the controls. When you use the <code>LoadControl( "ascx path" )</code> version it is given the page infront and hence does all the parsing and initalision.</p> <p>So in summary I need to change the code which is initalising the control and split it into seperate parts. I.e.</p> <pre><code>Control ErrorCntrl = LoadControl("ErrorDisplay.ascx"); ErrorCntrl.ID = SomeID; (ErrorCntrl as ErrorDisplay).SetErrorMessage = MessageDetail; divErrorContainer.Controls.Add(ErrorCntrl); </code></pre> <p>And it should work ok.. It isn't as neat as my previous attempt, but at least it will work.</p> <p>I am still open to suggestions to improve the above.</p> <p>Cheers</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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