detect submit button with httprequest?

D

Daniel

Hi all,

I am using .NET 1.1. I have a form with a cancel button, something like
this:

<form method="post"....>
<input type="submit" value="Submit">
<input type="submit" value="Cancel" id="btnCancel">

</form>


In the code behind, I am trying to use the Request object to see if the
cancel button was pushed (I have another button on the page also). I have
tried using:

Request["btnCancel"]
Request.Form["btnCancel"]
Request.Params["btnCancel"]

They all return null or empty string. I also tried Request["Cancel"] with
same results. These are in the page load method.

So, what is the best way to check to see which button was pushed?

Thanks in advance.
 
D

Daniel

Mark Rae said:
I am using .NET 1.1. I have a form with a cancel button, something like
this:

<form method="post"....>
<input type="submit" value="Submit">
<input type="submit" value="Cancel" id="btnCancel">

</form>

In the code behind, I am trying to use the Request object to see if the
cancel button was pushed (I have another button on the page also). I have
tried using:

Request["btnCancel"]
Request.Form["btnCancel"]
Request.Params["btnCancel"]

They all return null or empty string. I also tried Request["Cancel"] with
same results. These are in the page load method.

So, what is the best way to check to see which button was pushed?

I'm not quite sure what you're trying to do exactly, but this isn't the
way ASP.NET was designed to work at all...

One of the fundamental design goals of ASP.NET was precisely to eliminate
what you're seeing with the concept of the postback, e.g.

<form id="MyForm" runat="server">
<asp:Button ID="MySubmitButton" runat="server" Text="Submit"
OnClick="MySubmitButton_Click" />
<asp:Button ID="MyCancelButton" runat="server" Text="Cancel"
OnClick="MyCancelButton_Click" />
</form>

This means that you don't need to try to work out which button was
pressed, because when the Submit button is pressed MySubmitButton_Click()
will run and when the Cancel button is pressed MyCancelButton_Click() will
run...


--

I am trying to get more familiar with the .NET way to doing things. What I
was suggesting is more Java like.

Thanks, I appreciate it!
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top