Form controls and code behind

  • Thread starter Thread starter Roshawn Dawson
  • Start date Start date
R

Roshawn Dawson

Hi,

Suppose I have an form that contains any number of controls. To access
these controls programatically and get/set the state of their
properties, must they all be server controls (have the runat="server"
attribute)?

Thanks,
Roshawn
 
Roshawn,

If you mean server-side access, then yes. You can always access any controls
on client side.

Eliyahu
 
As long as the control is marked as runat="server" and has an ID it
should be accessible in the code behind as long as you define it inside
the main class.
 
This applies to the HTML controls in the HTML tab of your VS.NET toolbox:
If you want to access the controls from your server side code then yes, they
will need the runat="server" attribute.
If you don't need to interact with the controls at all, or if you only want
to interact with the controls with client side script, then you don't need
the runat="server" attribute on the control and it's best for performance
reasons to leave it off.

Here's more info:
http://SteveOrr.net/faq/3in1.aspx#ServerControl
 

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

Similar Threads

<form> tag question 3
Multiple form tags 2
HTMLInputRadioButton Question 1
Html form trouble 2
Export GridView to Excel Error 3
Html Form Help!!! 8
Forms and hidden fields 5
Forms collection in ASP.NET 3

Back
Top