J
justsome_newbie
Sorry for posting another question, but I can't seem to get the hang of
ASP.Net. In windows apps if I want to extend a control I would just
create a class that inherits from that control and do
add/overload/override the necessary properties and methods. This
apparently doesn't work in Asp.Net, or at least I can't get it to.
Take the simple class below:
public class MyTextBox : System.Web.UI.WebControls.TextBox
{
public MyTextBox()
{
}
public String HelloWorldText
{
get
{
return "Hello World";
}
}
public void ChangeText()
{
this.Text = this.HelloWorldText;
}
}
I then added the below to the host page to load the control (since I
couldn't find out how to do it at design time):
protected void Page_Load(object sender, EventArgs e)
{
Page.Controls.Add(new MyTextBox());
}
When run this fails with the error "Control 'ctl02' of type 'MyTextBox'
must be placed inside a form tag with runat=server."
I have no idea what this means (this is still my first ASP.Net app),
could any of you experts offer some guidance as to how I should extend
a control?
Thanks in advance!
ASP.Net. In windows apps if I want to extend a control I would just
create a class that inherits from that control and do
add/overload/override the necessary properties and methods. This
apparently doesn't work in Asp.Net, or at least I can't get it to.
Take the simple class below:
public class MyTextBox : System.Web.UI.WebControls.TextBox
{
public MyTextBox()
{
}
public String HelloWorldText
{
get
{
return "Hello World";
}
}
public void ChangeText()
{
this.Text = this.HelloWorldText;
}
}
I then added the below to the host page to load the control (since I
couldn't find out how to do it at design time):
protected void Page_Load(object sender, EventArgs e)
{
Page.Controls.Add(new MyTextBox());
}
When run this fails with the error "Control 'ctl02' of type 'MyTextBox'
must be placed inside a form tag with runat=server."
I have no idea what this means (this is still my first ASP.Net app),
could any of you experts offer some guidance as to how I should extend
a control?
Thanks in advance!