Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't response.write an asp:Button control

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
Hi,

I need to write out the following control using response.write:

<asp:Button id=&quot;btn1&quot; runat=&quot;Server&quot; />

Or an ImageButton. But it doesn't work. I can't see the control in the browser. And if I view --> source, I see the actual code:

<asp:Button id=&quot;btn1&quot; runat=&quot;Server&quot; />

My code is within the form tags. The only thing I can think of is that you cannot response.write a server control. Is this correct? And is there any way around this?

Thanks,
Mark
 
Your conclusion is correct. You cannot response.write server controls, because these are picked up by asp.net during page processing and rendered to regular HTML elements to be sent to the client.

The way to do this is something like (in your page load event)

dim btn as new button
btn.ClientID = &quot;btn1&quot; 'only do this if you really need to - normally, it is better and easier to allow asp.net to assign the client id
Me.Controls.add btn

HTH

Mark [openup]
 
In other words, controls need to be processed on the server, and all Response.Write does is add text to the client's page.

One useful bit of information I can contribute is that ASP.NET has PlaceHolder and Panel controls just for dynamically adding and/or grouping controls on your page.

The syntax would be similar to what you see in Custom's post: PlaceHolder.Controls.Add()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top