A
alun65
I'm having trouble programmatically adding a user control and then
setting some of it's server controls.
I add the user control to the code behind and add it to a placeholder:
protected void Page_Load(object sender, EventArgs e)
{
UserControls_WebUserControl myControl = new
UserControls_WebUserControl();
PlaceHolder1.Controls.Add(web);
}
And I make a reference to it on the webpage:
<%@ Register Src="~/UserControls/WebUserControl.ascx"
TagName="myUserControl" TagPrefix="CustomControl" %>
All good so far?
For the user contorl, to simplify it the the Page_Load of the user
control is trying to set a hyperlink text (as later on a will
hopefully pass a load of values to a constructor of the user control)
like so:
HyperLink1.Text = "Hi I'm a hyperlink";
I'm expecting the obvious (well obvious to me anyways). For one
hyperlink with the text "Hi I'm a hyperlink".
instead when I run this I get the error:
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
When debugging the hyperlink I've placed on the user control doesn't
seem to exist! Could any kind programmer tell this noobie what he's
doing wrong. Thanks in advance.
Alun
setting some of it's server controls.
I add the user control to the code behind and add it to a placeholder:
protected void Page_Load(object sender, EventArgs e)
{
UserControls_WebUserControl myControl = new
UserControls_WebUserControl();
PlaceHolder1.Controls.Add(web);
}
And I make a reference to it on the webpage:
<%@ Register Src="~/UserControls/WebUserControl.ascx"
TagName="myUserControl" TagPrefix="CustomControl" %>
All good so far?
For the user contorl, to simplify it the the Page_Load of the user
control is trying to set a hyperlink text (as later on a will
hopefully pass a load of values to a constructor of the user control)
like so:
HyperLink1.Text = "Hi I'm a hyperlink";
I'm expecting the obvious (well obvious to me anyways). For one
hyperlink with the text "Hi I'm a hyperlink".
instead when I run this I get the error:
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
When debugging the hyperlink I've placed on the user control doesn't
seem to exist! Could any kind programmer tell this noobie what he's
doing wrong. Thanks in advance.
Alun