detect submit button with httprequest?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

    detect submit button with httprequest?

    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 [MVP]

    #2
    Re: detect submit button with httprequest?

    "Daniel" <dhw4095@gmail. com.nospamwrote in message
    news:rJ__j.1013 23$y05.22157@ne wsfe22.lga...
    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="MySubmitBut ton" runat="server" Text="Submit"
    OnClick="MySubm itButton_Click" />
    <asp:Button ID="MyCancelBut ton" runat="server" Text="Cancel"
    OnClick="MyCanc elButton_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...


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Daniel

      #3
      Re: detect submit button with httprequest?


      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:%23sOpW9Ew IHA.4912@TK2MSF TNGP03.phx.gbl. ..
      "Daniel" <dhw4095@gmail. com.nospamwrote in message
      news:rJ__j.1013 23$y05.22157@ne wsfe22.lga...
      >
      >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.Para ms["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="MySubmitBut ton" runat="server" Text="Submit"
      OnClick="MySubm itButton_Click" />
      <asp:Button ID="MyCancelBut ton" runat="server" Text="Cancel"
      OnClick="MyCanc elButton_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!

      Comment

      • Mark Rae [MVP]

        #4
        Re: detect submit button with httprequest?

        "Daniel" <dhw4095@gmail. com.nospamwrote in message
        news:nNe%j.1019 69$y05.8051@new sfe22.lga...
        >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...
        >
        I am trying to get more familiar with the .NET way to doing things. What I
        was suggesting is more Java like.
        >
        ASP.NET bears very little (if any) resemblance to Java... Trying to learn
        ASP.NET with a Java mindset really isn't going to get you very far, IMO...

        Please don't take this as a patronising suggestion, but I strongly suggest
        you get a copy of this:


        and work your way through it...

        You'll probably find the learning curve quite steep at first, but that's
        more due to the .NET Framework than to ASP.NET itself...


        --
        Mark Rae
        ASP.NET MVP


        Comment

        Working...