473,320 Members | 2,107 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,320 software developers and data experts.

Question On Viewstate and ButtonClicks

OHM
Hi,

I'n new to ASP.NET and I have a question maybe someone could answer for me.

I realise that viewstate holds information about the state of the controls
such as the values of text boxes etc.

However, If I have two buttons on a form, how does ASP.NET know which one I
clicked on as they both submit. It cannot be the viewstate which is held
in a hidden field because this is generate when the page is output on
request or postback, so what is it that tells the ASP.NET that button1 was
pressed rather than button2.
I assume that something in the Request object does this, but what ?

TIA
Nov 18 '05 #1
6 892
OHM wrote:
Hi,

I'n new to ASP.NET and I have a question maybe someone could answer for me.

I realise that viewstate holds information about the state of the controls
such as the values of text boxes etc.

However, If I have two buttons on a form, how does ASP.NET know which one I
clicked on as they both submit. It cannot be the viewstate which is held
in a hidden field because this is generate when the page is output on
request or postback, so what is it that tells the ASP.NET that button1 was
pressed rather than button2.
I assume that something in the Request object does this, but what ?

TIA


The name of the button is transmitted to the page.
You can test this:

<html>
<body>
<form method="get" action="http://localhost/test.aspx">
<input type="submit" name="submitFirst" value="first" />
<input type="submit" name="submitSecond" value="second" />
</form>
</body>
</html>

method="get" to be able to see the name value pairs that are posted to
the server in the query string. If the method="post" the name value
pairs are hidden.
Notice the query string when you press the first and the second button
Nov 18 '05 #2
Thanks, is this visible in the clas hierarchy, in other words, can this be
determined prgamatically, or do we simply see this in terms of the events
fired.

Cheers - OHM
"bloomfield" <bl********@as.ro> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
OHM wrote:
Hi,

I'n new to ASP.NET and I have a question maybe someone could answer for me.
I realise that viewstate holds information about the state of the controls such as the values of text boxes etc.

However, If I have two buttons on a form, how does ASP.NET know which one I clicked on as they both submit. It cannot be the viewstate which is held in a hidden field because this is generate when the page is output on
request or postback, so what is it that tells the ASP.NET that button1 was pressed rather than button2.
I assume that something in the Request object does this, but what ?

TIA


The name of the button is transmitted to the page.
You can test this:

<html>
<body>
<form method="get" action="http://localhost/test.aspx">
<input type="submit" name="submitFirst" value="first" />
<input type="submit" name="submitSecond" value="second" />
</form>
</body>
</html>

method="get" to be able to see the name value pairs that are posted to
the server in the query string. If the method="post" the name value
pairs are hidden.
Notice the query string when you press the first and the second button

Nov 18 '05 #3
Actually, I found it, its in the following class instance

Request.form.AllKeys
"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks, is this visible in the clas hierarchy, in other words, can this be
determined prgamatically, or do we simply see this in terms of the events
fired.

Cheers - OHM
"bloomfield" <bl********@as.ro> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
OHM wrote:
Hi,

I'n new to ASP.NET and I have a question maybe someone could answer
for
me.
I realise that viewstate holds information about the state of the controls such as the values of text boxes etc.

However, If I have two buttons on a form, how does ASP.NET know which one I clicked on as they both submit. It cannot be the viewstate which is held in a hidden field because this is generate when the page is output on
request or postback, so what is it that tells the ASP.NET that button1 was pressed rather than button2.
I assume that something in the Request object does this, but what ?

TIA


The name of the button is transmitted to the page.
You can test this:

<html>
<body>
<form method="get" action="http://localhost/test.aspx">
<input type="submit" name="submitFirst" value="first" />
<input type="submit" name="submitSecond" value="second" />
</form>
</body>
</html>

method="get" to be able to see the name value pairs that are posted to
the server in the query string. If the method="post" the name value
pairs are hidden.
Notice the query string when you press the first and the second button


Nov 18 '05 #4
Actually, I found it, its in the following class instance

Request.form.AllKeys
"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks, is this visible in the clas hierarchy, in other words, can this be
determined prgamatically, or do we simply see this in terms of the events
fired.

Cheers - OHM
"bloomfield" <bl********@as.ro> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
OHM wrote:
Hi,

I'n new to ASP.NET and I have a question maybe someone could answer
for
me.
I realise that viewstate holds information about the state of the controls such as the values of text boxes etc.

However, If I have two buttons on a form, how does ASP.NET know which one I clicked on as they both submit. It cannot be the viewstate which is held in a hidden field because this is generate when the page is output on
request or postback, so what is it that tells the ASP.NET that button1 was pressed rather than button2.
I assume that something in the Request object does this, but what ?

TIA


The name of the button is transmitted to the page.
You can test this:

<html>
<body>
<form method="get" action="http://localhost/test.aspx">
<input type="submit" name="submitFirst" value="first" />
<input type="submit" name="submitSecond" value="second" />
</form>
</body>
</html>

method="get" to be able to see the name value pairs that are posted to
the server in the query string. If the method="post" the name value
pairs are hidden.
Notice the query string when you press the first and the second button


Nov 18 '05 #5
Hi OHM,

Yes, in addition to using the different name to distinguish the buttons
,when the page be postedback (because of the button submit events),
there'll exist a certain item in the Request.Forms collection which
indicate which button cause the submit post back. Generally this is
apparent to the developers since ASP.NET runtime will handle it and
determine which event handler be called. But if you have interests , you
can manually loop it and found it. :)
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
Thank you for your time and effort.

Regards - OHM

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:oC**************@cpmsftngxa10.phx.gbl...
Hi OHM,

Yes, in addition to using the different name to distinguish the buttons
,when the page be postedback (because of the button submit events),
there'll exist a certain item in the Request.Forms collection which
indicate which button cause the submit post back. Generally this is
apparent to the developers since ASP.NET runtime will handle it and
determine which event handler be called. But if you have interests , you
can manually loop it and found it. :)
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7

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

Similar topics

2
by: Mike P | last post by:
I have the following code in my Page_Load event to populate a listbox from a database : if (!(Page.IsPostBack)) { SqlConnection objConnection = new...
5
by: Craig Buchanan | last post by:
I'm using a viewstate key/value to store a serialized instance of a class. If I redirect to another aspx page, the viewstate is lost. Is this the intended behavior of the viewstate? Is there a...
1
by: Raed Sawalha | last post by:
Hi I have created a usercontrol in which I save a value in viewstate like this: ViewState=value; If I use the same key (ViewState=value;) in my master page, does the framework recognize where the...
6
by: Chris | last post by:
I've created two textboxes and one button on my web form. I then set the EnableViewState property of Textbox1 to False. Textbox2 is set to True. The button has no code in it - It simply has an...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
6
by: Bryan | last post by:
I've got an ASP.NET application running that has a non-visual user interface (it's a voice app using VXML.) The voice client understands cookies and when it requests and aspx page, what actually...
5
by: Mark Olbert | last post by:
I have a composite control (under ASPNET2; derived from CompositeControl) which contains a label. The contents of the label are set when the control is created to a user-supplied value. What's...
2
by: Carly | last post by:
Hi, I am now not sure I understand what ViewState does. Having EnableViewState=true or false on a WEB form and/or different server controls does not seem to make any difference. I am just...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.