runat server?

  • Thread starter Thread starter Steve Bywaters
  • Start date Start date
S

Steve Bywaters

(In my transition from ASP to ASP.NET)

*When* would I use at "runat server" tag on a button, as opposed to a normal
button?

If I set up a search area on a page, with a 'Search' button that applies the
entered items to the db - is that best as a normal button or server
control.... and why?

Steve
 
There is an awful lot that can be said about this but in a nutshell:

Server Controls provide the developer with an easy and rich way of applying
server-side compiled code to the control. Normal HTML controls (without the
runat=server) can only be programmed client-side.

Server Controls render themselves as pure HTML and possibly JavaScript, so
they are browser safe, but can provide very rich functionality (validation
controls, calendar, datagrid, etc.).

Server Controls maintain their own state between page calls, HTML controls
do not.

In short, use Server Controls when you want to be able to program events for
the control on the server and/or have the control maintain its own state.

Use standard HTML controls when you don't need/want this functionality and
don't want the overhead associated with them.

Use HTML Server controls (standard HTML controls with runat=server added to
them) when you are taking an existing classic HTML/ASP application and want
to upgrade it to ASP.NET without having to create all new controls on the
page.
 
Thank you for that!
So let's see if I've got it....<g>

To submit a bunch of parameters for a database search, I need some kind of
button.. but which?:

* I don't want to use an asp:button, because I don't need the extra
functionality
* I could add a normal HTML button and add "run at=server"... but why?
* I might as well just use a conventional HTML button, to submit the form
with the search parameters - yes?

Steve
 
To submit a bunch of parameters for a database search, I need some kind of
button.. but which?:
* I don't want to use an asp:button, because I don't need the extra
functionality

Ok, then don't use this one.
* I could add a normal HTML button and add "run at=server"... but why?

I only suggest this when you are taking an existing Classic HTML or ASP
page and are upgrading it to .NET and you need to have the benefits of a
server control. If you don't need those benefits, then you don't need this
either.
* I might as well just use a conventional HTML button, to submit the form
with the search parameters - yes?

Sounds good to me!

The basic rule is simple, use standard HTML controls if they will do the
job. If you need server-side programmability or you need the control to
maintain its own state or you need a control that the standard HTML controls
don't offer (calendar, validation control, etc.) then go for the Server
Controls.
 
Back
Top