473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

runat="server" attribute in submit button

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!!
Nov 18 '05 #1
5 2078
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).

--
With the best wishes,
Shaul Feldman
"Matt" <ma*******@hotmail.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
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!!

Nov 18 '05 #2
Jos
Matt wrote:
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

--

Jos
Nov 18 '05 #3
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
Nov 18 '05 #4
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"
Nov 18 '05 #5
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" <an*******@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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.

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: Libra Blue | last post by:
I try to set the page title dynamically in an aspx page, but sometimes an error occurs due to VS removing the runat="server" attribute at its own will... How do I stop from doing so?? Libra Blue
1
by: Matt | last post by:
If the web control has runat="server" attribute, can we say that control is built on the server (on the fly), and not static control?? Please advise.
4
by: COHENMARVIN | last post by:
I'm a asp programmer starting out with asp.net. I understand that an asp form can post to its own page and that this allows validation of form fields on the server. But suppose all the controls...
4
by: Ryan | last post by:
Hello, I have a standard HTML button on an aspx web form that I have set to runat server. The button is named reset1 and its tag is as follows: <INPUT id="btnReset1" style="WIDTH: 60px;...
11
by: gunjan.mait | last post by:
hi, i wanted to know the exact use of runat="server" which is being used is ASP.NET why we every time need to use it, even when i want to do the work at client side? How to do simple processings...
1
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is...
2
by: Bob | last post by:
Hi, in aspx file, i defined this: <input id="Button2" type="button" value="button" runat="server" onclick="klik()"/> This 'onclick' event is a clientclick (starting the Javascript function...
4
by: Chris | last post by:
Hi, i 'm experimenting with postback and i tried that with a button server control and an Html input button but with runat="server". The button server control causes a postback, but not the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.