c# - Why are my dynamically added user controls showing having their ascx controls as null? -


i created new control testcontrol. on front-end gave it

<asp:label id="lbltest" runat="server" /> 

on backend:

public partial class testcontrol : system.web.ui.usercontrol {     protected void page_load(object sender, eventargs e)     {         lbltest.text = "blah";     } } 

when load control via:

        var control1 = loadcontrol(typeof(testcontrol), null);         controls.add(control1); 

i exception lbltest null.

why occurring?

use relative path overload of loadcontrol method instead, noted here.

http://msdn.microsoft.com/en-us/library/ewtd66a0.aspx

edit: changed answer after research.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -