Groups | Blog | Home
all groups > asp.net > march 2005 >

asp.net : runat server on codebehind


Ferryandi
3/12/2005 8:49:36 PM
hi, i have created a button link like this and attach it
to placeholder in code behind

linkbutton1 = New LinkButton
linkbutton1.Text = "Link Button
linkbutton1.ID = "Link1"
PlaceHolderLink.Controls.Add(linkbutton1)

but how do i add runat="server" as in html code in code
behind, im using vb.net
Peter Rilling
3/12/2005 9:03:26 PM
Runat is only used by ASP.NET to indicate static tags that will be mapped to
variables in the code-behind. If you dynamically create those controls,
then you have to initialize the controls on each postback. You have to do
this manually when the form initializes.

[quoted text, click to view]

Derek Harmon
3/13/2005 12:11:43 AM
[quoted text, click to view]

You don't need to add runat="server" to a dynamically-created control. LinkButton
extends System.Web.UI.Control, so it's already understood by ASP.NET as being
a server-side control (as opposed to client-side controls like <INPUT type="submit">
buttons that have no existence on the server.)

runat="server" is something written in the .ASPX file, if you had created this LinkButton
statically in that file (in what perhaps is confusingly called the "HTML View" although it
is not) you would've written,

<asp:LinkButton ID="Link1" Text="Link Button" runat="server"></asp:LinkButton>

Go and do that and then run the web application in your browser, and do a View Source.
You should never see runat="server" in the HTML.


Derek Harmon

Juan T. Llibre
3/13/2005 1:02:41 AM
If it's in the code-behind, it automatically runs at the server.

Instancing any server control in
code-behind makes it run server-side.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

[quoted text, click to view]

AddThis Social Bookmark Button