How to differentiate between click event of multiple server buttons

Discussion in 'ASP .Net' started by mayur_hirpara@hotmail.com, Jun 5, 2006.

  1. Guest

    Hi,
    I have been developing web applications for a while now.
    However, as I was thinking through the architecture I really don't
    understand the "How server can identify between which buttons has made
    the postback request.???"
    for e.g.
    I have a webpage default.aspx.
    I place TWO or more server buttons on it.
    Create server-side event handlers for each of the buttons.

    Now run the application. If I look at the source HTML generated, it
    shows "INPUT" element of type "SUBMIT" for each of the buttons and
    since it is "SUBMIT" button it does not have any onclick event
    associated with it by default.

    I am really puzzled on ...
    HOW server determines which button has been clicked.

    because each time I click different button it really fireas the
    appropriate event handlers on the serverr which is correct. But just
    want to understand the underlying wiring.
    Any lights on this will be greatly appreciated.
    Thanks
    --Mike
     
    , Jun 5, 2006
    #1
    1. Advertising

  2. the wiring is pretty simple. a submit button, is a html form element. take
    this simple html, with a text box and two submits.
    <html>
    <body>
    <form name=f1 method=post action="foo1.aspx">
    <input type=hidden name=input1 value=hiddenvalue>
    <input type=submit name=submit1 value=submit value=value1>
    <input type=submit name=submit2 value=submit value=value2>
    <button name=button1 value=value3
    onclick="document.forms[0].submit()">
    </form>
    </body>
    </html>

    if the use clicks on submit button, the browser does a form post including
    the name/value pairs of the form elements (input, submit, select and
    textarea). there are some rules on which elements are included.

    if type=submit button will only be posted if clicked.
    if type=checkbox will be included if checked == true
    if type=radio will be included if checked == true
    the element must be enabled to postbcak its value
    if type=image, must be clicked and also sends name_x and name_y values.

    if the user clicks submit1, the postback data is

    input1=hiddenvalue@submit1=value1

    if the user clicks submit2, the postback data is

    input1=hiddenvalue@submit2=value2

    if the user clicks button1, the postback data is

    input1=hiddenvalue

    as buttons (which are not a form elements) do not post back values, and a
    script triggered postback will not include any type=submit values.

    for auto postback controls (like the dropdown), client script fills in a
    hidden field named "__EVENTTARGET", where the postback control name is
    written, then the client script calls "form.submit()", which will not
    include any submit buttons in the postback data.

    note: you can also have more than one form, but only the element values of
    one of the forms is postedback.


    -- bruce (sqlwork.com)


    <> wrote in message
    news:...
    > Hi,
    > I have been developing web applications for a while now.
    > However, as I was thinking through the architecture I really don't
    > understand the "How server can identify between which buttons has made
    > the postback request.???"
    > for e.g.
    > I have a webpage default.aspx.
    > I place TWO or more server buttons on it.
    > Create server-side event handlers for each of the buttons.
    >
    > Now run the application. If I look at the source HTML generated, it
    > shows "INPUT" element of type "SUBMIT" for each of the buttons and
    > since it is "SUBMIT" button it does not have any onclick event
    > associated with it by default.
    >
    > I am really puzzled on ...
    > HOW server determines which button has been clicked.
    >
    > because each time I click different button it really fireas the
    > appropriate event handlers on the serverr which is correct. But just
    > want to understand the underlying wiring.
    > Any lights on this will be greatly appreciated.
    > Thanks
    > --Mike
    >
     
    bruce barker \(sqlwork.com\), Jun 5, 2006
    #2
    1. Advertising

  3. Lit Guest

    Bruce,

    If my checkbox was checked to begin with and I uncheck it before I hit the
    Submit button then the server knows that I unchecked the checkbox just
    because its value was not posted back? What was the reason to have such
    rules? more efficient?
    Where did "<input type=hidden name=input1 value=hiddenvalue>" come from?
    Auto generated?

    what is value=submit value=value1 < causing error
    do you have an example that works and well formed <html> or xhtml

    Lit




    "bruce barker (sqlwork.com)" <> wrote
    in message news:...
    > the wiring is pretty simple. a submit button, is a html form element. take
    > this simple html, with a text box and two submits.
    > <html>
    > <body>
    > <form name=f1 method=post action="foo1.aspx">
    > <input type=hidden name=input1 value=hiddenvalue>
    > <input type=submit name=submit1 value=submit value=value1>
    > <input type=submit name=submit2 value=submit value=value2>
    > <button name=button1 value=value3
    > onclick="document.forms[0].submit()">
    > </form>
    > </body>
    > </html>
    >
    > if the use clicks on submit button, the browser does a form post including
    > the name/value pairs of the form elements (input, submit, select and
    > textarea). there are some rules on which elements are included.
    >
    > if type=submit button will only be posted if clicked.
    > if type=checkbox will be included if checked == true
    > if type=radio will be included if checked == true
    > the element must be enabled to postbcak its value
    > if type=image, must be clicked and also sends name_x and name_y values.
    >
    > if the user clicks submit1, the postback data is
    >
    > input1=hiddenvalue@submit1=value1
    >
    > if the user clicks submit2, the postback data is
    >
    > input1=hiddenvalue@submit2=value2
    >
    > if the user clicks button1, the postback data is
    >
    > input1=hiddenvalue
    >
    > as buttons (which are not a form elements) do not post back values, and a
    > script triggered postback will not include any type=submit values.
    >
    > for auto postback controls (like the dropdown), client script fills in a
    > hidden field named "__EVENTTARGET", where the postback control name is
    > written, then the client script calls "form.submit()", which will not
    > include any submit buttons in the postback data.
    >
    > note: you can also have more than one form, but only the element values of
    > one of the forms is postedback.
    >
    >
    > -- bruce (sqlwork.com)
    >
    >
    > <> wrote in message
    > news:...
    >> Hi,
    >> I have been developing web applications for a while now.
    >> However, as I was thinking through the architecture I really don't
    >> understand the "How server can identify between which buttons has made
    >> the postback request.???"
    >> for e.g.
    >> I have a webpage default.aspx.
    >> I place TWO or more server buttons on it.
    >> Create server-side event handlers for each of the buttons.
    >>
    >> Now run the application. If I look at the source HTML generated, it
    >> shows "INPUT" element of type "SUBMIT" for each of the buttons and
    >> since it is "SUBMIT" button it does not have any onclick event
    >> associated with it by default.
    >>
    >> I am really puzzled on ...
    >> HOW server determines which button has been clicked.
    >>
    >> because each time I click different button it really fireas the
    >> appropriate event handlers on the serverr which is correct. But just
    >> want to understand the underlying wiring.
    >> Any lights on this will be greatly appreciated.
    >> Thanks
    >> --Mike
    >>

    >
    >
     
    Lit, Jun 6, 2006
    #3
  4. Guest

    Hi Bruce,
    Excellent...Marvelous...
    I was looking for exactly such explanation. Thanks.
    I am really oblidged for explaining me this stuff. I was really not
    aware what is packed in an envelope when a button of type submit is
    clicked.
    Coupld you please post a link where I can read about this very BASIC
    rules of how what elements of a form is posted. Because sometime I use
    readonly textboxes and sometimes they are disables and I set is values
    using javascript and when I postback I get values for some controls
    while not for other controls depending on whether they are READONLY or
    Disabled.
    Thanks again for sharing this basic but very important to remember
    technics.
    --Mike



    bruce barker (sqlwork.com) wrote:
    > the wiring is pretty simple. a submit button, is a html form element. take
    > this simple html, with a text box and two submits.
    > <html>
    > <body>
    > <form name=f1 method=post action="foo1.aspx">
    > <input type=hidden name=input1 value=hiddenvalue>
    > <input type=submit name=submit1 value=submit value=value1>
    > <input type=submit name=submit2 value=submit value=value2>
    > <button name=button1 value=value3
    > onclick="document.forms[0].submit()">
    > </form>
    > </body>
    > </html>
    >
    > if the use clicks on submit button, the browser does a form post including
    > the name/value pairs of the form elements (input, submit, select and
    > textarea). there are some rules on which elements are included.
    >
    > if type=submit button will only be posted if clicked.
    > if type=checkbox will be included if checked == true
    > if type=radio will be included if checked == true
    > the element must be enabled to postbcak its value
    > if type=image, must be clicked and also sends name_x and name_y values.
    >
    > if the user clicks submit1, the postback data is
    >
    > input1=hiddenvalue@submit1=value1
    >
    > if the user clicks submit2, the postback data is
    >
    > input1=hiddenvalue@submit2=value2
    >
    > if the user clicks button1, the postback data is
    >
    > input1=hiddenvalue
    >
    > as buttons (which are not a form elements) do not post back values, and a
    > script triggered postback will not include any type=submit values.
    >
    > for auto postback controls (like the dropdown), client script fills in a
    > hidden field named "__EVENTTARGET", where the postback control name is
    > written, then the client script calls "form.submit()", which will not
    > include any submit buttons in the postback data.
    >
    > note: you can also have more than one form, but only the element values of
    > one of the forms is postedback.
    >
    >
    > -- bruce (sqlwork.com)
    >
    >
    > <> wrote in message
    > news:...
    > > Hi,
    > > I have been developing web applications for a while now.
    > > However, as I was thinking through the architecture I really don't
    > > understand the "How server can identify between which buttons has made
    > > the postback request.???"
    > > for e.g.
    > > I have a webpage default.aspx.
    > > I place TWO or more server buttons on it.
    > > Create server-side event handlers for each of the buttons.
    > >
    > > Now run the application. If I look at the source HTML generated, it
    > > shows "INPUT" element of type "SUBMIT" for each of the buttons and
    > > since it is "SUBMIT" button it does not have any onclick event
    > > associated with it by default.
    > >
    > > I am really puzzled on ...
    > > HOW server determines which button has been clicked.
    > >
    > > because each time I click different button it really fireas the
    > > appropriate event handlers on the serverr which is correct. But just
    > > want to understand the underlying wiring.
    > > Any lights on this will be greatly appreciated.
    > > Thanks
    > > --Mike
    > >
     
    , Jun 6, 2006
    #4
  5. Guest

    Hi Lit,
    As I understand, It it is server side CheckBox and its viewstate is
    TRUE then server can easily differentiate between the true and false
    value when user changes it.
    When it constructs the page object while postback operation it will
    create all server side controls within the page andd set its properties
    using "__ViewState". After that it checks to see the posted values and
    applies them.
    Now if the checkbox was originally checked then its value will be there
    in "__ViewState". If user clears it and performs a PostBack then server
    will first create checkbox with its original value i.e. checked=TRUE.
    Then it will query the posted values in the Request.Form() collection.
    If it does not find a checkbox in collection (as stated in Bruce's
    post, if a checkbox is cleared it is not postedback) then the framework
    will clear the checkbox value i.e. Checked=FALSE.
    I hope this answers your question.
    --Mike

    Lit wrote:
    > Bruce,
    >
    > If my checkbox was checked to begin with and I uncheck it before I hit the
    > Submit button then the server knows that I unchecked the checkbox just
    > because its value was not posted back? What was the reason to have such
    > rules? more efficient?
    > Where did "<input type=hidden name=input1 value=hiddenvalue>" come from?
    > Auto generated?
    >
    > what is value=submit value=value1 < causing error
    > do you have an example that works and well formed <html> or xhtml
    >
    > Lit
    >
    >
    >
    >
    > "bruce barker (sqlwork.com)" <> wrote
    > in message news:...
    > > the wiring is pretty simple. a submit button, is a html form element. take
    > > this simple html, with a text box and two submits.
    > > <html>
    > > <body>
    > > <form name=f1 method=post action="foo1.aspx">
    > > <input type=hidden name=input1 value=hiddenvalue>
    > > <input type=submit name=submit1 value=submit value=value1>
    > > <input type=submit name=submit2 value=submit value=value2>
    > > <button name=button1 value=value3
    > > onclick="document.forms[0].submit()">
    > > </form>
    > > </body>
    > > </html>
    > >
    > > if the use clicks on submit button, the browser does a form post including
    > > the name/value pairs of the form elements (input, submit, select and
    > > textarea). there are some rules on which elements are included.
    > >
    > > if type=submit button will only be posted if clicked.
    > > if type=checkbox will be included if checked == true
    > > if type=radio will be included if checked == true
    > > the element must be enabled to postbcak its value
    > > if type=image, must be clicked and also sends name_x and name_y values.
    > >
    > > if the user clicks submit1, the postback data is
    > >
    > > input1=hiddenvalue@submit1=value1
    > >
    > > if the user clicks submit2, the postback data is
    > >
    > > input1=hiddenvalue@submit2=value2
    > >
    > > if the user clicks button1, the postback data is
    > >
    > > input1=hiddenvalue
    > >
    > > as buttons (which are not a form elements) do not post back values, and a
    > > script triggered postback will not include any type=submit values.
    > >
    > > for auto postback controls (like the dropdown), client script fills in a
    > > hidden field named "__EVENTTARGET", where the postback control name is
    > > written, then the client script calls "form.submit()", which will not
    > > include any submit buttons in the postback data.
    > >
    > > note: you can also have more than one form, but only the element values of
    > > one of the forms is postedback.
    > >
    > >
    > > -- bruce (sqlwork.com)
    > >
    > >
    > > <> wrote in message
    > > news:...
    > >> Hi,
    > >> I have been developing web applications for a while now.
    > >> However, as I was thinking through the architecture I really don't
    > >> understand the "How server can identify between which buttons has made
    > >> the postback request.???"
    > >> for e.g.
    > >> I have a webpage default.aspx.
    > >> I place TWO or more server buttons on it.
    > >> Create server-side event handlers for each of the buttons.
    > >>
    > >> Now run the application. If I look at the source HTML generated, it
    > >> shows "INPUT" element of type "SUBMIT" for each of the buttons and
    > >> since it is "SUBMIT" button it does not have any onclick event
    > >> associated with it by default.
    > >>
    > >> I am really puzzled on ...
    > >> HOW server determines which button has been clicked.
    > >>
    > >> because each time I click different button it really fireas the
    > >> appropriate event handlers on the serverr which is correct. But just
    > >> want to understand the underlying wiring.
    > >> Any lights on this will be greatly appreciated.
    > >> Thanks
    > >> --Mike
    > >>

    > >
    > >
     
    , Jun 6, 2006
    #5
  6. Guest

    Hi Bruce,
    Excellent...Marvelous...
    I was looking for exactly such explanation. Thanks.
    I am really oblidged for explaining me this stuff. I was really not
    aware what is packed in an envelope when a button of type submit is
    clicked.
    Coupld you please post a link where I can read about this very BASIC
    rules of how what elements of a form is posted. Because sometime I use
    readonly textboxes and sometimes they are disables and I set is values
    using javascript and when I postback I get values for some controls
    while not for other controls depending on whether they are READONLY or
    Disabled.
    Thanks again for sharing this basic but very important to remember
    technics.
    --Mike


    bruce barker (sqlwork.com) wrote:
    > the wiring is pretty simple. a submit button, is a html form element. take
    > this simple html, with a text box and two submits.
    > <html>
    > <body>
    > <form name=f1 method=post action="foo1.aspx">
    > <input type=hidden name=input1 value=hiddenvalue>
    > <input type=submit name=submit1 value=submit value=value1>
    > <input type=submit name=submit2 value=submit value=value2>
    > <button name=button1 value=value3
    > onclick="document.forms[0].submit()">
    > </form>
    > </body>
    > </html>
    >
    > if the use clicks on submit button, the browser does a form post including
    > the name/value pairs of the form elements (input, submit, select and
    > textarea). there are some rules on which elements are included.
    >
    > if type=submit button will only be posted if clicked.
    > if type=checkbox will be included if checked == true
    > if type=radio will be included if checked == true
    > the element must be enabled to postbcak its value
    > if type=image, must be clicked and also sends name_x and name_y values.
    >
    > if the user clicks submit1, the postback data is
    >
    > input1=hiddenvalue@submit1=value1
    >
    > if the user clicks submit2, the postback data is
    >
    > input1=hiddenvalue@submit2=value2
    >
    > if the user clicks button1, the postback data is
    >
    > input1=hiddenvalue
    >
    > as buttons (which are not a form elements) do not post back values, and a
    > script triggered postback will not include any type=submit values.
    >
    > for auto postback controls (like the dropdown), client script fills in a
    > hidden field named "__EVENTTARGET", where the postback control name is
    > written, then the client script calls "form.submit()", which will not
    > include any submit buttons in the postback data.
    >
    > note: you can also have more than one form, but only the element values of
    > one of the forms is postedback.
    >
    >
    > -- bruce (sqlwork.com)
    >
    >
    > <> wrote in message
    > news:...
    > > Hi,
    > > I have been developing web applications for a while now.
    > > However, as I was thinking through the architecture I really don't
    > > understand the "How server can identify between which buttons has made
    > > the postback request.???"
    > > for e.g.
    > > I have a webpage default.aspx.
    > > I place TWO or more server buttons on it.
    > > Create server-side event handlers for each of the buttons.
    > >
    > > Now run the application. If I look at the source HTML generated, it
    > > shows "INPUT" element of type "SUBMIT" for each of the buttons and
    > > since it is "SUBMIT" button it does not have any onclick event
    > > associated with it by default.
    > >
    > > I am really puzzled on ...
    > > HOW server determines which button has been clicked.
    > >
    > > because each time I click different button it really fireas the
    > > appropriate event handlers on the serverr which is correct. But just
    > > want to understand the underlying wiring.
    > > Any lights on this will be greatly appreciated.
    > > Thanks
    > > --Mike
    > >
     
    , Jun 6, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger
    Replies:
    1
    Views:
    649
    GreggTB
    May 20, 2005
  2. Replies:
    13
    Views:
    801
    Richard Tobin
    Aug 11, 2004
  3. Jo
    Replies:
    7
    Views:
    507
  4. Bob Weiner
    Replies:
    1
    Views:
    139
    Elton W
    May 6, 2005
  5. Replies:
    1
    Views:
    162
    Peter Michaux
    Apr 27, 2007
Loading...

Share This Page