how do I determine which button is clicked with HTML control?

Discussion in 'ASP .Net Web Controls' started by Samuel, Jul 26, 2005.

  1. Samuel

    Samuel Guest

    hi,

    Here is the problem: I was trying to build a page with the RadioButtonList
    control, but due to the interface requirement, the individual buttons are
    scattered (not in the same location) in the page which makes it impossible to
    use this control. I am thinking about using the HTML radio control like the
    following:

    <input type="radio" name="group" value="1" runat="server">
    <input type="radio" name="group" value="2" runat="server">
    <input type="radio" name="group" value="3" runat="server">

    but I am not sure how to determine which button is clicked in the code
    behind page. I know each one of the button has to have a unique id, but then
    how am I supposed to determine which one of them is selected? I know with
    RadioButtonList, I can do RadioButtonList1.SelectedItem.text, but I am not
    sure what to do with HTML radio controls.
    Samuel, Jul 26, 2005
    #1
    1. Advertising

  2. Hi Welcome to ASPNET newsgroup.

    From your description, you've some Radio buttons on the asp.net webpages
    and located in separate sections, and you're wondering a means to
    centrallly control the check status changing of all those radios, yes?

    As for the radio buttons, are they nested in some otther container
    controls? Also, do you think it ok that we still use the ASP.NET
    RadioButton server controls, currently I've got the following two options:

    1. Still use ASP.NET RadioButton Server Control, since the RadioButton
    control has the "CheckedChanged" event, we can register a common event
    handler for all those radio buttons and determine which one's event is
    fired in the event handler (through the "sender" parameter).

    2. Use Html RadioInput control, since the html control doesn't have
    postback event, we need to use clientside script to hook its onclick
    (client side DHTML event) and log the result into a html input hidden field

    <input type="hidden" .... runat="server" /> so that when the page
    postback, we can read the info from that html input hidden field.

    How do you think of these ones? If you have any other ideas or questions,
    please feel free to post here.

    Thanks & Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)





    --------------------
    | Thread-Topic: how do I determine which button is clicked with HTML
    control?
    | thread-index: AcWSFwTyEJ8bcUfcQyWgyLNNpK567Q==
    | X-WBNR-Posting-Host: 64.180.224.155
    | From: =?Utf-8?B?U2FtdWVs?= <>
    | Subject: how do I determine which button is clicked with HTML control?
    | Date: Tue, 26 Jul 2005 12:20:01 -0700
    | Lines: 17
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:10098
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | hi,
    |
    | Here is the problem: I was trying to build a page with the
    RadioButtonList
    | control, but due to the interface requirement, the individual buttons are
    | scattered (not in the same location) in the page which makes it
    impossible to
    | use this control. I am thinking about using the HTML radio control like
    the
    | following:
    |
    | <input type="radio" name="group" value="1" runat="server">
    | <input type="radio" name="group" value="2" runat="server">
    | <input type="radio" name="group" value="3" runat="server">
    |
    | but I am not sure how to determine which button is clicked in the code
    | behind page. I know each one of the button has to have a unique id, but
    then
    | how am I supposed to determine which one of them is selected? I know with
    | RadioButtonList, I can do RadioButtonList1.SelectedItem.text, but I am
    not
    | sure what to do with HTML radio controls.
    |
    Steven Cheng[MSFT], Jul 27, 2005
    #2
    1. Advertising

  3. Samuel

    Samuel Guest

    Thanks Steve for your response. Let me clarify a few things.

    1) I was not going to use the RadioButton control, but the RadiobuttonList
    control, like this

    <asp:RadioButtonList ID="deleteoption" runat="server"
    RepeatDirection="Horizontal">
    <asp:ListItem Value="deleteonly">Delete the file
    Only</asp:ListItem>
    <asp:ListItem Value="deleteandrun">Execute the file,
    and if no error occurs, delete it.</asp:ListItem>
    </asp:RadioButtonList>

    2) Because of the design requirement of the page, if I insist on using the
    Radiobuttonlist, I will have a few other controls inside the
    <asp:RadioButtonList></asp:RadioButtonList> tags, which is not supported at
    all. The RadioButtonList is not nested inside other controls.

    3) I dont need to autopostback whenever a selection changes

    4) I was wondering how I could determine which one of the radiobutton is
    selected on postback if I have the following grouped radio buttons (note the
    values for the name attribute are the same, which means they are grouped..):

    <input type="radio" name="group" value="1" runat="server">
    <input type="radio" name="group" value="2" runat="server">
    <input type="radio" name="group" value="3" runat="server">

    Typically you can check RadioButtonList1.SelectedItem.text if you use
    RadioButtonList, but in my case I can't.

    Please let me know your thought.
    Samuel, Jul 27, 2005
    #3
  4. Thanks for your followup.

    Yes, in fact, I mentioned the RadioButton control just because we can use
    multi RadioButton server controls on our page and register a single
    eventhandler for their checkedChanged event. (No Autopostback needed), this
    is a way of retrieving which one of those radio buttons is checked when
    postback, RadioButton has a "GroupName" property just represent the "name"
    attribute of the html <input type="radio" ...> element.

    Well, if we still need to use the <input type="radio" ....> , there're also
    a simple way to get the current selected value of a group of radio
    elements. That's the Request.Form collection. As we know, all the html
    input element's value will be post back to server side( when the page/form
    is submited), these values are stored in the Request.Form collection as
    name/value pairs. For those html input radios with the same "name"
    attribute, the Request.Form["name"] just contains the currently checked
    one's value. For example, if we have the following radio buttons on page:

    <INPUT id="irOne" type="radio" name="cg" value="One" runat="server"> One
    <INPUT id="irTwo" type="radio" name="cg" value="Two" runat="server"> Two
    <INPUT id="irThree" type="radio" name="cg" value="Three" runat="server">
    Three
    <INPUT id="irFour" type="radio" name="cg" value="Four" runat="server"> Four

    When postback, in the serverside code, we can use the below statement to
    retreive the currently checked one's value:

    string cgValue;
    cgValue = Request.Form["cg"];



    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)






    --------------------
    | Thread-Topic: how do I determine which button is clicked with HTML
    control?
    | thread-index: AcWSc+yHpkREB3OATZadELa08DgpCA==
    | X-WBNR-Posting-Host: 64.180.224.155
    | From: =?Utf-8?B?U2FtdWVs?= <>
    | References: <>
    <>
    | Subject: RE: how do I determine which button is clicked with HTML control?
    | Date: Tue, 26 Jul 2005 23:25:03 -0700
    | Lines: 32
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:10103
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | Thanks Steve for your response. Let me clarify a few things.
    |
    | 1) I was not going to use the RadioButton control, but the
    RadiobuttonList
    | control, like this
    |
    | <asp:RadioButtonList ID="deleteoption" runat="server"
    | RepeatDirection="Horizontal">
    | <asp:ListItem Value="deleteonly">Delete the file
    | Only</asp:ListItem>
    | <asp:ListItem Value="deleteandrun">Execute the
    file,
    | and if no error occurs, delete it.</asp:ListItem>
    | </asp:RadioButtonList>
    |
    | 2) Because of the design requirement of the page, if I insist on using
    the
    | Radiobuttonlist, I will have a few other controls inside the
    | <asp:RadioButtonList></asp:RadioButtonList> tags, which is not supported
    at
    | all. The RadioButtonList is not nested inside other controls.
    |
    | 3) I dont need to autopostback whenever a selection changes
    |
    | 4) I was wondering how I could determine which one of the radiobutton is
    | selected on postback if I have the following grouped radio buttons (note
    the
    | values for the name attribute are the same, which means they are
    grouped..):
    |
    | <input type="radio" name="group" value="1" runat="server">
    | <input type="radio" name="group" value="2" runat="server">
    | <input type="radio" name="group" value="3" runat="server">
    |
    | Typically you can check RadioButtonList1.SelectedItem.text if you use
    | RadioButtonList, but in my case I can't.
    |
    | Please let me know your thought.
    |
    Steven Cheng[MSFT], Jul 28, 2005
    #4
  5. Samuel

    Samuel Guest

    Thanks Steven for your reply. It was helpful

    Can you show me a simple code how to register a single event handler to
    handle multiple radiobutton's (with same groupname) checkedChanged event
    without postback in VB.NET?

    Thanks very much!
    Samuel, Jul 28, 2005
    #5
  6. Samuel

    Samuel Guest

    never mind my previous post.. I misread your comment. I got it.
    Samuel, Jul 28, 2005
    #6
  7. You're welcome ,

    I'm also glad that my suggestions is of assistance.

    Thanks & Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | Thread-Topic: how do I determine which button is clicked with HTML
    control?
    | thread-index: AcWTNCVsv9p+EVJdQLi0Z+ad1lmqZQ==
    | X-WBNR-Posting-Host: 64.180.224.155
    | From: =?Utf-8?B?U2FtdWVs?= <>
    | References: <>
    <>
    <>
    <In4i#>
    | Subject: RE: how do I determine which button is clicked with HTML control?
    | Date: Wed, 27 Jul 2005 22:21:02 -0700
    | Lines: 7
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:10129
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | Thanks Steven for your reply. It was helpful
    |
    | Can you show me a simple code how to register a single event handler to
    | handle multiple radiobutton's (with same groupname) checkedChanged event
    | without postback in VB.NET?
    |
    | Thanks very much!
    |
    Steven Cheng[MSFT], Jul 28, 2005
    #7
    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. Daniel Walzenbach
    Replies:
    2
    Views:
    8,607
    Steven Cheng[MSFT]
    Jun 2, 2004
  2. bthumber
    Replies:
    4
    Views:
    473
    bthumber
    Jun 25, 2010
  3. Jim Mitchell

    How to determine which control in a template column was clicked...

    Jim Mitchell, Jul 28, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    119
    Joel .NET
    Oct 29, 2003
  4. Yossi

    Which button was clicked and on which row?

    Yossi, Nov 17, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    733
    Yossi
    Nov 17, 2006
  5. Jim Mitchell
    Replies:
    0
    Views:
    199
    Jim Mitchell
    Jul 12, 2003
Loading...

Share This Page