detect submit button with httprequest?

  • Thread starter Thread starter Daniel
  • Start date Start date
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.
 
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!
 
Back
Top