Form controls and code behind

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
 
E

Eliyahu Goldin

Roshawn,

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

Eliyahu
 
L

luminousc

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.
 
S

Steve C. Orr [MVP, MCSD]

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top