Friday, January 16, 2009

ASP.NET runat="server" attribute

Some thought about ASP.NET runat="server" attribute

The runat="server" attribute indicates that the control should be processed on the server

in the ASP.NET
<- input type="text" id="myTextBox" runat="server" / ->
And <- input type="text" id="myTextBox" / -> are different,

The <- input type="text" id="myTextBox" runat="server" / -> sent to the sever and sever assign the new id (clientid) for it

But, <- input type="text" id="myTextBox" / -> not sent to server and the id (clientid) not change

One example, if you put a user control into a master page, and this user control contains

<- input type="text" id="mytxtRunServer" runat="server" / ->

<- input type="text" id="mytxt" / ->



Run the application ( include the master page ), in your browser to view source you will see


<- input name="ctl00$myct1$mytxtRunServer" type="text" id="ctl00_myct1_mytxtRunServer" / ->

<- input type="text" id="mytxt" / ->


<- input type="text" id="mytxtRunServer" runat="server" / ->

The id changed to be id="ctl00_myct1_mytxtRunServer"
But <- input type="text" id="mytxt" / ->

There is nothing change.

It is useful to help you use you javascript getElementById(‘’) function

No comments:

iphone 3gs review