asp.net form post

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

    #1

    asp.net form post

    hii im working on asp.net and i have a form which has 4 asp.net buttons ech
    time i click on a button the page is posted now i want to know on pageload
    which button has caused the post action.. of the page ...this is would help
    me to write button specific events on tht page ....can any one help out in
    this .....


  • John Saunders

    #2
    Re: asp.net form post

    "LIN" <junkvaluesnota llowed@football .com> wrote in message
    news:uwJxI5lXDH A.2620@TK2MSFTN GP09.phx.gbl...[color=blue]
    > hii im working on asp.net and i have a form which has 4 asp.net buttons[/color]
    ech[color=blue]
    > time i click on a button the page is posted now i want to know on pageload
    > which button has caused the post action.. of the page ...this is would[/color]
    help[color=blue]
    > me to write button specific events on tht page ....can any one help out in
    > this .....[/color]

    Why not simply handle the Click events for all four buttons?
    --
    John Saunders
    Internet Engineer
    john.saunders@s urfcontrol.com


    Comment

    • LIN

      #3
      Re: asp.net form post

      im actually writing a few lines of code on the click event of the button
      ...thts not the problem i want to capture the name of the button wheen the
      form is posted i.e after the button is being clicked..i want to know which
      button has made the form to post..

      "John Saunders" <john.saunders@ surfcontrol.com > wrote in message
      news:uW45F7lXDH A.2352@TK2MSFTN GP12.phx.gbl...[color=blue]
      > "LIN" <junkvaluesnota llowed@football .com> wrote in message
      > news:uwJxI5lXDH A.2620@TK2MSFTN GP09.phx.gbl...[color=green]
      > > hii im working on asp.net and i have a form which has 4 asp.net buttons[/color]
      > ech[color=green]
      > > time i click on a button the page is posted now i want to know on[/color][/color]
      pageload[color=blue][color=green]
      > > which button has caused the post action.. of the page ...this is would[/color]
      > help[color=green]
      > > me to write button specific events on tht page ....can any one help out[/color][/color]
      in[color=blue][color=green]
      > > this .....[/color]
      >
      > Why not simply handle the Click events for all four buttons?
      > --
      > John Saunders
      > Internet Engineer
      > john.saunders@s urfcontrol.com
      >
      >[/color]


      Comment

      • Steve C. Orr, MCSD

        #4
        Re: asp.net form post

        From within your Page_Load event you can look for the names of the buttons
        in the Request.Form collection.
        If the button name is present then you know that button caused the postback.

        --
        I hope this helps,
        Steve C. Orr, MCSD



        "LIN" <junkvaluesnota llowed@football .com> wrote in message
        news:uwJxI5lXDH A.2620@TK2MSFTN GP09.phx.gbl...[color=blue]
        > hii im working on asp.net and i have a form which has 4 asp.net buttons[/color]
        ech[color=blue]
        > time i click on a button the page is posted now i want to know on pageload
        > which button has caused the post action.. of the page ...this is would[/color]
        help[color=blue]
        > me to write button specific events on tht page ....can any one help out in
        > this .....
        >
        >[/color]


        Comment

        • Carl Prothman [MVP]

          #5
          Re: asp.net form post

          "LIN" <junkvaluesnota llowed@football .com> wrote[color=blue]
          > im actually writing a few lines of code on the click event of the button
          > ..that is not the problem I want to capture the name of the button when the
          > form is posted i.e after the button is being clicked..I want to know which
          > button has made the form to post..
          >[/color]

          Lin,
          Given a Button WebControl
          <asp:Button id="Button1" Runat="server" Text="Button1"> </asp:Button>

          You can get the Button ID and Text as follows:

          Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
          Dim myButton As Button = CType(sender, Button)
          Dim myButtonID As String = myButton.ID
          Dim myButtonName As String = myButton.Text
          End Sub

          --

          Thanks,
          Carl Prothman
          Microsoft ASP.NET MVP





          Comment

          • Steve C. Orr, MCSD

            #6
            Re: asp.net form post

            From within your Page_Load event you can look for the names of the buttons
            in the Request.Form collection.
            If the button name is present then you know that button caused the postback.

            --
            I hope this helps,
            Steve C. Orr, MCSD



            "LIN" <junkvaluesnota llowed@football .com> wrote in message
            news:uwJxI5lXDH A.2620@TK2MSFTN GP09.phx.gbl...[color=blue]
            > hii im working on asp.net and i have a form which has 4 asp.net buttons[/color]
            ech[color=blue]
            > time i click on a button the page is posted now i want to know on pageload
            > which button has caused the post action.. of the page ...this is would[/color]
            help[color=blue]
            > me to write button specific events on tht page ....can any one help out in
            > this .....
            >
            >[/color]


            Comment

            • LIN

              #7
              Re: asp.net form post

              ok now i can find the button in the request.form on page load section ...for
              wht do i check it for ....
              pls note tht the button im using here is image button..pls lemme know

              thanx
              "Steve C. Orr, MCSD" <Steve@Orr.ne t> wrote in message
              news:e6xtuhqXDH A.3724@tk2msftn gp13.phx.gbl...[color=blue]
              > From within your Page_Load event you can look for the names of the buttons
              > in the Request.Form collection.
              > If the button name is present then you know that button caused the[/color]
              postback.[color=blue]
              >
              > --
              > I hope this helps,
              > Steve C. Orr, MCSD
              > http://Steve.Orr.net
              >
              >
              > "LIN" <junkvaluesnota llowed@football .com> wrote in message
              > news:uwJxI5lXDH A.2620@TK2MSFTN GP09.phx.gbl...[color=green]
              > > hii im working on asp.net and i have a form which has 4 asp.net buttons[/color]
              > ech[color=green]
              > > time i click on a button the page is posted now i want to know on[/color][/color]
              pageload[color=blue][color=green]
              > > which button has caused the post action.. of the page ...this is would[/color]
              > help[color=green]
              > > me to write button specific events on tht page ....can any one help out[/color][/color]
              in[color=blue][color=green]
              > > this .....
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • LIN

                #8
                Re: asp.net form post

                hii this is working for only a single button when i have more than a single
                button and write the same code below ..both the button's are getting
                executed ....i.e i get the messages from both the buttons ...wht do i do
                now ..and one more thing the button im using here is an image button and not
                a normal button

                thanx


                "Carl Prothman [MVP]" <carlpr@spamcop .net> wrote in message
                news:#1OzCXoXDH A.1640@TK2MSFTN GP10.phx.gbl...[color=blue]
                > "LIN" <junkvaluesnota llowed@football .com> wrote[color=green]
                > > im actually writing a few lines of code on the click event of the button
                > > ..that is not the problem I want to capture the name of the button when[/color][/color]
                the[color=blue][color=green]
                > > form is posted i.e after the button is being clicked..I want to know[/color][/color]
                which[color=blue][color=green]
                > > button has made the form to post..
                > >[/color]
                >
                > Lin,
                > Given a Button WebControl
                > <asp:Button id="Button1" Runat="server" Text="Button1"> </asp:Button>
                >
                > You can get the Button ID and Text as follows:
                >
                > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As[/color]
                System.EventArg s) Handles Button1.Click[color=blue]
                > Dim myButton As Button = CType(sender, Button)
                > Dim myButtonID As String = myButton.ID
                > Dim myButtonName As String = myButton.Text
                > End Sub
                >
                > --
                >
                > Thanks,
                > Carl Prothman
                > Microsoft ASP.NET MVP
                > http://www.able-consulting.com
                >
                >
                >
                >[/color]


                Comment

                • Carl Prothman [MVP]

                  #9
                  Re: asp.net form post

                  "LIN" <junkvaluesnota llowed@football .com> wrote[color=blue]
                  > hii this is working for only a single button when i have more than a single
                  > button and write the same code below ..both the button's are getting
                  > executed ....i.e i get the messages from both the buttons ...wht do i do
                  > now ..
                  > and one more thing the button im using here is an image button and not
                  > a normal button
                  >[/color]

                  Given two ImageButton WebControls

                  <asp:ImageButto n id="ImageButton 1" runat="server" ImageUrl="image 1.jpg" />
                  <asp:ImageButto n id="ImageButton 2" runat="server" ImageUrl="image 2.jpg" />

                  The events handlers (and code to get each ID) looks like:

                  Private Sub ImageButton1_Cl ick(ByVal sender As System.Object, _
                  ByVal e As System.Web.UI.I mageClickEventA rgs) Handles ImageButton1.Cl ick

                  Dim myImageButton As ImageButton = CType(sender, ImageButton)
                  Dim myImageButtonID As String = myImageButton.I D
                  End Sub

                  Private Sub ImageButton2_Cl ick(ByVal sender As System.Object, _
                  ByVal e As System.Web.UI.I mageClickEventA rgs) Handles ImageButton2.Cl ick

                  Dim myImageButton As ImageButton = CType(sender, ImageButton)
                  Dim myImageButtonID As String = myImageButton.I D
                  End Sub

                  When you click on a single ImageButton, the corresponding click event handler fires,
                  not both. If you are seeing both click event handlers fire for a single click on one of
                  the ImageButton, then post some sample code which repros the problem.

                  --

                  Thanks,
                  Carl Prothman
                  Microsoft ASP.NET MVP


                  [color=blue]
                  > thanx
                  >
                  >
                  > "Carl Prothman [MVP]" <carlpr@spamcop .net> wrote in message
                  > news:#1OzCXoXDH A.1640@TK2MSFTN GP10.phx.gbl...[color=green]
                  > > "LIN" <junkvaluesnota llowed@football .com> wrote[color=darkred]
                  > > > im actually writing a few lines of code on the click event of the button
                  > > > ..that is not the problem I want to capture the name of the button when[/color][/color]
                  > the[color=green][color=darkred]
                  > > > form is posted i.e after the button is being clicked..I want to know[/color][/color]
                  > which[color=green][color=darkred]
                  > > > button has made the form to post..
                  > > >[/color]
                  > >
                  > > Lin,
                  > > Given a Button WebControl
                  > > <asp:Button id="Button1" Runat="server" Text="Button1"> </asp:Button>
                  > >
                  > > You can get the Button ID and Text as follows:
                  > >
                  > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As[/color]
                  > System.EventArg s) Handles Button1.Click[color=green]
                  > > Dim myButton As Button = CType(sender, Button)
                  > > Dim myButtonID As String = myButton.ID
                  > > Dim myButtonName As String = myButton.Text
                  > > End Sub
                  > >
                  > > --
                  > >
                  > > Thanks,
                  > > Carl Prothman
                  > > Microsoft ASP.NET MVP
                  > > http://www.able-consulting.com
                  > >
                  > >
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  Working...