How to set runat property to html input controls

Posted by Sunitajadhav under Regular Expressions on 1/27/2010 | Views : 2805 | Status : [Member] | Replies : 4
Hello friends,
I have done web application in .net framework 2.0 and now converted into .net 3.5.How to set runat property to html input controls?
Thanks in advance.




Responses

Posted by: Abhi2434 on: 1/27/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Basically runat=server determines if the control is visible through codebehind or not. Html controls can have runat=server.

Just place
<input type="text" runat="server" id="txtbox" />

Now you can refer to the control using txtbox in the codebehind. Asp.NET actually builds a class in the server by parsing the html you write in design. It puts all the controls that are declared as runat=server as class members, and also places the other controls (which are actually not declared as runat=server) as internal properties.

During the rendering of the page, it writes the response taking all the controls(both).
Now the question is when you need to use Runat=server. If you are using runat=server it actually places the value of the whole control in viewstate to maintain the pagestate, which is actually absent for others.
So runat server control increases the page size by writing elements in viewstate.

So if you dont need to update a control from the server side, you shouldnt be using the runat=server to that control.
Provided, you can easily get the value of a control which is not declared as runat=server using
Request.Form["controlid"]

I hope it is clear now.

www.abhisheksur.com

Sunitajadhav, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunitajadhav on: 1/27/2010 [Member] Starter

Up
0
Down
Hello Abhi,
I got it now.But when i click on button then it does not show view code rather than it shows source code.I want view code when i click on button.
Thanks in advance

Sunitajadhav, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 1/27/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Are you talking about the designer?

I never try working on the designer. I always write my own html.
Actually in the design view, the default behavior of Visual Studio is defined to add a handler to the runat=server button and open code for you.
If you dont like that, you can easily switch to the html design view and do whatever you like.

It is actually a default behavior of Visual Studio.
Please let me know if you still have any issue .

:)

www.abhisheksur.com

Sunitajadhav, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/27/2010 [Member] Bronze

Up
0
Down
Sunita

You can try like this. If it is a html button drag the button to the designer. Right click ==> you will get a context menu to make it for run at server. Just click on that menu. Designer will generate the code runat="server" code for you. Then double click on the button you will be directed to the codebehind direclty....


Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Sunitajadhav, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response