473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2107
Hi,
from what I have seen, runat="server" allows you programmaticall y 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*******@hotm ail.com> wrote in message
news:eY******** ******@tk2msftn gp13.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 "SelectedIndexC hanged" 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_ServerC lick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles submit1.ServerC lic

....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 "SelectedIndexC hanged" 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*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ***********@mic rosoft.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 "SelectedIndexC hanged" 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
8403
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
3
1444
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
1591
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
1670
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 turn out to be valid, and now I want to move to a new page? My form declaration looks like this: <form METHOD="POST" ACTION="sites2.aspx" name="MyForm" runat="server"> This form declaration is on a page called sites1.aspx, but it doesn't post any...
4
6535
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; HEIGHT: 24px" type="reset" value="Reset" name="btnReset1" runat="server"> Using Interdev I then double click the button in design view and in the code behind page (aspx.vb) have the following:
11
2564
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 like displaying some message at client side only without hitting server? what is the use of onclick, as we have to use onserverclick always? why it is not possible to do the things without using runat="server" in script?
1
2439
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 invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
2
2327
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 "klik()" ). I want to do a 'server onclick', just like the <asp:Buttoncontrol, but it
4
13308
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 Html input button with runat="server". Can someone explain me why (because it's running on the server)? Thanks
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.