Adding Controls at run time

  • Thread starter Praveen Naregal
  • Start date
P

Praveen Naregal

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton' must be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal
 
F

Felbrigg

What it means is that the html element you are trying to add this control to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);
 
P

Praveen Naregal

Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

Felbrigg said:
What it means is that the html element you are trying to add this control to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Praveen Naregal said:
Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton' must be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal
 
F

Felbrigg

Do you mean that you are creating the HTML at run time as well as the asp
controls?


Praveen Naregal said:
Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

Felbrigg said:
What it means is that the html element you are trying to add this
control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);
must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal
 
P

Praveen Naregal

Hi Felbrigg,

Yes.I am trying to create the controls run time as at run time only I come
to how many controls I have to create.

Regards,
Praveen

Felbrigg said:
Do you mean that you are creating the HTML at run time as well as the asp
controls?


Praveen Naregal said:
Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

Felbrigg said:
What it means is that the html element you are trying to add this
control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton'
must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal
 
S

Sangwoo Im

Praveen Naregal said:
Hi Felbrigg,

Yes.I am trying to create the controls run time as at run time only I come
to how many controls I have to create.

Regards,
Praveen

Felbrigg said:
Do you mean that you are creating the HTML at run time as well as the asp
controls?


Praveen Naregal said:
Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

What it means is that the html element you are trying to add this
control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton'
must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal


May I see your code? not the part but whole?
I wonder where you placed the linkbutton control.
and are you making composite custom control?
 
A

Alessandro Zifiglio

Your error state :
I am getting the following error. HttpException (0x80004005): Control
'lButton' of type 'LinkButton'
must be placed inside a form tag with runat=server.

Its very clear. All asp.net web control need to placed btw <form id="form1"
......runat="server">
<asp:LinkButton ....></asp:LinkButton>
</form>

now when you add your control dynamically either you add it to a placeholder
control, or another controls, control collection, which is already in btw
the form object with runat="server" or you add your control to the form
objects controls collection.

what you are doing is, you are adding a label to YOur pages controls
collection, and then adding a link button to your labels controls
collection. And NONE of this is going into your form objects controls
collection. So instead of adding it to the pages controls collection add it
to the pages form object.

Let me know if your having difficulty. This is very simple and not as
complicated as it seems.
Praveen Naregal said:
Hi Felbrigg,

Yes.I am trying to create the controls run time as at run time only I come
to how many controls I have to create.

Regards,
Praveen

Felbrigg said:
Do you mean that you are creating the HTML at run time as well as the asp
controls?


Praveen Naregal said:
Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

What it means is that the html element you are trying to add this control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton' must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at runtime?

Thanks in advance
Praveen Naregal
 
P

Praveen Naregal

Hi all,

I got the problem.It's rather very simple. You need to include
the following line and set the runat=server property.
lbAcnt.Attributes.Add("runat","server");

thanks for your suggestions
Praveen

Alessandro Zifiglio said:
Your error state :
I am getting the following error. HttpException (0x80004005): Control
'lButton' of type 'LinkButton'
must be placed inside a form tag with runat=server.

Its very clear. All asp.net web control need to placed btw <form id="form1"
.....runat="server">
<asp:LinkButton ....></asp:LinkButton>
</form>

now when you add your control dynamically either you add it to a placeholder
control, or another controls, control collection, which is already in btw
the form object with runat="server" or you add your control to the form
objects controls collection.

what you are doing is, you are adding a label to YOur pages controls
collection, and then adding a link button to your labels controls
collection. And NONE of this is going into your form objects controls
collection. So instead of adding it to the pages controls collection add it
to the pages form object.

Let me know if your having difficulty. This is very simple and not as
complicated as it seems.
Praveen Naregal said:
Hi Felbrigg,

Yes.I am trying to create the controls run time as at run time only I come
to how many controls I have to create.

Regards,
Praveen

Felbrigg said:
Do you mean that you are creating the HTML at run time as well as the asp
controls?


Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this runat=server
attribute while creating the control runtime?

Regards,
Praveen

What it means is that the html element you are trying to add this
control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton'
must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at
runtime?

Thanks in advance
Praveen Naregal
 
A

Alessandro Zifiglio

I dont know where your getting at. I have very clearly explained how this
works. Which parts didnt you get ? ;P
Praveen Naregal said:
Hi all,

I got the problem.It's rather very simple. You need to include
the following line and set the runat=server property.
lbAcnt.Attributes.Add("runat","server");

thanks for your suggestions
Praveen

Alessandro Zifiglio said:
Your error state :
I am getting the following error. HttpException (0x80004005): Control
'lButton' of type 'LinkButton'
must be placed inside a form tag with runat=server.

Its very clear. All asp.net web control need to placed btw <form id="form1"
.....runat="server">
<asp:LinkButton ....></asp:LinkButton>
</form>

now when you add your control dynamically either you add it to a placeholder
control, or another controls, control collection, which is already in btw
the form object with runat="server" or you add your control to the form
objects controls collection.

what you are doing is, you are adding a label to YOur pages controls
collection, and then adding a link button to your labels controls
collection. And NONE of this is going into your form objects controls
collection. So instead of adding it to the pages controls collection add it
to the pages form object.

Let me know if your having difficulty. This is very simple and not as
complicated as it seems.
Praveen Naregal said:
Hi Felbrigg,

Yes.I am trying to create the controls run time as at run time only I come
to how many controls I have to create.

Regards,
Praveen

Do you mean that you are creating the HTML at run time as well as
the
asp
controls?


Hi Felbrigg,

I am using Visual Studio .NET and C#. How do you specify this
runat=server
attribute while creating the control runtime?

Regards,
Praveen

What it means is that the html element you are trying to add this
control
to
must have a "runat=server" attribute, such as this...

<TD id="test" runat=server></TD>

You will also have to add the button to a controls collection of the
container like this.

test.Controls.Add(lblAcnt);

Hi all,

I am trying to add linkbuttons at run time. Here is the code.

//....
System.Web.UI.WebControls.LinkButton lbAcnt = new
System.Web.UI.WebControls.LinkButton();
Controls.Add(lbAcnt);
lbAcnt.ID = "lButton" ;
lbAcnt.Enabled = true;
lbAcnt.Visible = true;
lbAcnt.Text = "lButton" ;
lbAcnt.Click += new System.EventHandler(this.DisplayAcntDetails);
//..

I am getting the following error.
HttpException (0x80004005): Control 'lButton' of type 'LinkButton'
must
be
placed inside a form tag with runat=server.]

What is wrong here. How to set these runat = server property at
runtime?

Thanks in advance
Praveen Naregal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top