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

S

Samuel

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.
 
S

Steven Cheng[MSFT]

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?= <[email protected]>
| 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: <[email protected]>
| 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.
|
 
S

Samuel

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.
 
S

Steven Cheng[MSFT]

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?= <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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.
|
 
S

Samuel

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!
 
S

Steven Cheng[MSFT]

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?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<In4i#[email protected]>
| 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: <[email protected]>
| 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!
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top