R
Robbie
I have a Web Form with some tailored logos and artwork. The web form
also has a user control that has typical registration info on it
(Name, Company Name, etc.) One of the fields, a TextBox, is a
PromoCode which is a field required for each company which registers.
I want to programatically set the value of this PromoCode in the host
web-form's Page_Load method, but I can't seem to do it.
My user control is "RegisterInfo.ascx" (On the page it is rendered as
"RegisterInfo1")
My main web page is Register.aspx
In the Register.aspx.cs code-behind file I would like to do something
like:
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterInfo1.PromoCode.Text = "PROMOCODE";
}
But, of course, it didn't work. So, I tried...
private void Page_Load(object sender, System.EventArgs e)
{
RegisterInfo r = new RegisterInfo();
r._promoCode.Text = "PROMOCODE";
}
And in the user control Register.ascx, I had this:
public string _promoCode
{
get
{return this.PromoCode.Text; // "PromoCode" is the TextBox object.
}
set
{PromoCode.Text = value;
}
}
This complies fine, but I get an "Object reference not set to an
instance of an object." error.
Specifically, how do I set the value of a TextBox in a user control
from the code-behind file? This is not very clear!
Thanks in advance!
also has a user control that has typical registration info on it
(Name, Company Name, etc.) One of the fields, a TextBox, is a
PromoCode which is a field required for each company which registers.
I want to programatically set the value of this PromoCode in the host
web-form's Page_Load method, but I can't seem to do it.
My user control is "RegisterInfo.ascx" (On the page it is rendered as
"RegisterInfo1")
My main web page is Register.aspx
In the Register.aspx.cs code-behind file I would like to do something
like:
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterInfo1.PromoCode.Text = "PROMOCODE";
}
But, of course, it didn't work. So, I tried...
private void Page_Load(object sender, System.EventArgs e)
{
RegisterInfo r = new RegisterInfo();
r._promoCode.Text = "PROMOCODE";
}
And in the user control Register.ascx, I had this:
public string _promoCode
{
get
{return this.PromoCode.Text; // "PromoCode" is the TextBox object.
}
set
{PromoCode.Text = value;
}
}
This complies fine, but I get an "Object reference not set to an
instance of an object." error.
Specifically, how do I set the value of a TextBox in a user control
from the code-behind file? This is not very clear!
Thanks in advance!