runat="server" attribute in submit button

M

Matt

I want to know what is the purpose of runat="server" attribute??

For example, for a submit button, it just submit the form data to the
server, whats the differences between

<input type="submit" name="submit1">
<input type="submit" name="submit1" runat="server">

Please advise! Thanks!!
 
S

Shaul Feldman

Hi,
from what I have seen, runat="server" allows you programmatically use HTML
controls on the server side, plus to keep their values in ViewState. This is
quiet neat, since they are lightweight and do the job. The only thing I
found inconvinient is that ListBox, for instance, doesn't save the
SelectedIndex value on it's way back to server (PostBack).
 
J

Jos

Matt said:
I want to know what is the purpose of runat="server" attribute??

For example, for a submit button, it just submit the form data to the
server, whats the differences between

<input type="submit" name="submit1">
<input type="submit" name="submit1" runat="server">

Please advise! Thanks!!

In the case of the submit button, the runat="server" attribute will
be rarely necessary.

But you need it if, for instance, you want to change the value
(the text on the button) from code:

If(Adding) Then
submit1.Value = "Add"
Else
submit1.Value = "Update"
End If
 
G

Guest

I agree. ViewState is the deal. As far as List Boxes are concerned, you can always explicitly save the selected value in ViewState. Just one line of code in a "SelectedIndexChanged" event. Easy enough to do

Actually, by using runat="server" your making the "HTML Control" a "Web Control" which is, in effect an object that is easily manipulated on the server and which renders HTML just before the page is sent to the browser. In addition to ViewState, Web Controls give you an event model for handling things like changes in values, selected items, submitted buttons, etc

You'll see a lot of other benefits as you get into designing your own controls, nesting controls within other controls - it's a whole new world
 
G

Guest

It also means that you can write an event procedure for it. Something like this..

Private Sub submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit1.ServerClic

....do your thing here..

End Su

So, if there's several buttons, you can deal with each one differently

Try it - that won't work without runat="server"
 
S

Shaul Feldman

Hi,
I agree with you on "SelectedIndexChanged" event, the problem is that it
makes an extra PostBack. Sometimes I preffer to stay at client and not to
postback at all. My solution was to send the SelectedIndex as a parameter
when the main postback (from my application's point of view) was commited.

--
With the best wishes,
Shaul Feldman
Rich said:
I agree. ViewState is the deal. As far as List Boxes are concerned, you
can always explicitly save the selected value in ViewState. Just one line
of code in a "SelectedIndexChanged" event. Easy enough to do.
Actually, by using runat="server" your making the "HTML Control" a "Web
Control" which is, in effect an object that is easily manipulated on the
server and which renders HTML just before the page is sent to the browser.
In addition to ViewState, Web Controls give you an event model for handling
things like changes in values, selected items, submitted buttons, etc.
You'll see a lot of other benefits as you get into designing your own
controls, nesting controls within other controls - it's a whole new world.
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top