473,785 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Groupname for Radiobutton kills Listener from Buttons?

I have the following problem (especially with the groupname-attribut of the
RadioButton-Control) when developing in Visual Studio 2005 Beta.

I load an ascx-control in an aspx-page. This ascx-control itself creates
dynamically many radiobuttons in this way:
foreach (DataRow radiobutton_ite m in rbl_values.Rows )
{
RadioButton single_radiobut ton = new RadioButton();
single_radiobut ton.ID = "idname";
single_radiobut ton.GroupName = "groupname" ;
this.Page.Contr ols.Add(single_ radiobutton);
}

When loading the aspx-Page (and its controls) everything is fine and
groupname works as it should (I could only select one of the group). But when
a postback to this site occurs it seems that the listener of the
submit_button (placed on the aspx-Page) is killed. When I do not define the
Groupname of the RadioButton the submit_button works as it should (listeners
are not killed?!) but I can select more than only one radiobutton as I don't
have a group which they belong to.

I tried it already with an alternative:

single_radiobut ton.Attributes. Add("name", mygroupname) instead of
single_radiobut ton.GroupName = "groupname" ; (seen in
http://msdn.microsoft.com/newsgroups...7ec&sloc=en-us)

but this didn't help.

Do you knwo this issue?
Nov 19 '05 #1
3 3077
Where is your call to build the button list?
Is this being triggered from the Page_Load? If so, did you do the IsPostBack
check?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"visual2005beta _developer" wrote:
I have the following problem (especially with the groupname-attribut of the
RadioButton-Control) when developing in Visual Studio 2005 Beta.

I load an ascx-control in an aspx-page. This ascx-control itself creates
dynamically many radiobuttons in this way:
foreach (DataRow radiobutton_ite m in rbl_values.Rows )
{
RadioButton single_radiobut ton = new RadioButton();
single_radiobut ton.ID = "idname";
single_radiobut ton.GroupName = "groupname" ;
this.Page.Contr ols.Add(single_ radiobutton);
}

When loading the aspx-Page (and its controls) everything is fine and
groupname works as it should (I could only select one of the group). But when
a postback to this site occurs it seems that the listener of the
submit_button (placed on the aspx-Page) is killed. When I do not define the
Groupname of the RadioButton the submit_button works as it should (listeners
are not killed?!) but I can select more than only one radiobutton as I don't
have a group which they belong to.

I tried it already with an alternative:

single_radiobut ton.Attributes. Add("name", mygroupname) instead of
single_radiobut ton.GroupName = "groupname" ; (seen in
http://msdn.microsoft.com/newsgroups...7ec&sloc=en-us)

but this didn't help.

Do you knwo this issue?

Nov 19 '05 #2
Hi Curt,

I've added my minimalized version below.

I experimented a bit more and can now substantiate the error (when it occurs
and how to reproduce).

If I use the attached code as it is (the line "single_radiobu tton.GroupName
= rbl.ID;" in the ascx-file "inputRadiobutt onlist.ascx" is not commented out)
and I take the following steps:
1) choose none of the radios
2) hit "submit"
--> button-method "Button1_Cl ick" (from "default.as px") is called correctly
(displays <DateTime.Now >)
3) choose one of the radios (only one possible)
4) hit "submit"
--> button-method "Button1_Cl ick" (from "default.as px") is NOT called

The same happens if close the site and reopen it and then choose at the
first step one radio (button-method won't be called).

If I comment only the line "single_radiobu tton.GroupName = rbl.ID;" out
everything works fine (except that I can choose both radiobuttons) but the
button-method will be called everytime when hitting "submit".

File "Default.as px" contains the following placeholder and button:

<form id="form1" runat="server">
<asp:PlaceHolde r ID="ph" runat="server"> </asp:PlaceHolder >
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="submit" />
</form>

File "Default.aspx.c s":

public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
Control c = (Control)this.L oadControl("inp utRadiobuttonli st.ascx");

this.ph.Control s.Add(c);
}
protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( "button method called "+
DateTime.Now.To LongTimeString( ));
}
}

File "inputRadiobutt onlist.ascx":

<%@ Control Language="C#" AutoEventWireup ="true"
CodeFile="input Radiobuttonlist .ascx.cs" Inherits="input Radiobuttonlist " %>
<tr><td colspan=3><asp: Label ID="rbl_text" runat="server"
Text="Label"></asp:Label>
<asp:CustomVali dator ID="valid_rbl" runat="server"
ErrorMessage="C ustomValidator"
EnableClientScr ipt="False"></asp:CustomValid ator></td>
</tr>
<tr><td colspan=3><asp: Table ID="rbl" runat="server">
</asp:Table></td></tr>

File "inputRadiobutt onlist.ascx.cs" :

public partial class inputRadiobutto nlist : System.Web.UI.U serControl
{
private const string mandatory = "mandatory" ;

protected void Page_Load(objec t sender, EventArgs e)
{
this.rbl_text.I D = "snippetid" ;
this.rbl_text.T ext = "snippet_te xt";
this.rbl.ID = "radiobutto ns";

if (mandatory.Inde xOf("mandatory" ) != -1)
{
this.rbl_text.T ext += "*";

}

//just to have some radiobbutons to add
DataTable rbl_values = new DataTable();
rbl_values.Colu mns.Add("choice _text");
rbl_values.Colu mns.Add("choice _value");
DataRow first_row = rbl_values.NewR ow();
first_row["choice_tex t"] = "yes";
first_row["choice_val ue"] = "y";
rbl_values.Rows .Add(first_row) ;
DataRow scnd_row = rbl_values.NewR ow();
scnd_row["choice_tex t"] = "no";
scnd_row["choice_val ue"] = "n";
rbl_values.Rows .Add(scnd_row);
//adding the radiobuttons dynamically
TableRow single_row = new TableRow();
foreach (DataRow radiobutton_ite m in rbl_values.Rows )
{

TableCell single_cell0 = new TableCell();

RadioButton single_radiobut ton = new RadioButton();

string radiobutton_id =
radiobutton_ite m["choice_val ue"].ToString();
single_radiobut ton.ID = radiobutton_id;
//single_radiobut ton.Attributes. Add("name", rbl.ID);
single_radiobut ton.GroupName = rbl.ID;

single_cell0.Co ntrols.Add(sing le_radiobutton) ;
single_row.Cell s.Add(single_ce ll0);

TableCell single_cell1 = new TableCell();

Label radiobutton_tex t = new Label();
radiobutton_tex t.Text =
radiobutton_ite m["choice_tex t"].ToString();

single_cell1.Co ntrols.Add(radi obutton_text);
single_row.Cell s.Add(single_ce ll1);

}

rbl.Controls.Ad d(single_row);

this.rbl_text.F oreColor = System.Drawing. Color.Black;

this.valid_rbl. ErrorMessage = "";

}
}

--------------------------------------------------------------------------------------------------
"Curt_C [MVP]" wrote:
Where is your call to build the button list?
Is this being triggered from the Page_Load? If so, did you do the IsPostBack
check?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"visual2005beta _developer" wrote:
I have the following problem (especially with the groupname-attribut of the
RadioButton-Control) when developing in Visual Studio 2005 Beta.

I load an ascx-control in an aspx-page. This ascx-control itself creates
dynamically many radiobuttons in this way:
foreach (DataRow radiobutton_ite m in rbl_values.Rows )
{
RadioButton single_radiobut ton = new RadioButton();
single_radiobut ton.ID = "idname";
single_radiobut ton.GroupName = "groupname" ;
this.Page.Contr ols.Add(single_ radiobutton);
}

When loading the aspx-Page (and its controls) everything is fine and
groupname works as it should (I could only select one of the group). But when
a postback to this site occurs it seems that the listener of the
submit_button (placed on the aspx-Page) is killed. When I do not define the
Groupname of the RadioButton the submit_button works as it should (listeners
are not killed?!) but I can select more than only one radiobutton as I don't
have a group which they belong to.

I tried it already with an alternative:

single_radiobut ton.Attributes. Add("name", mygroupname) instead of
single_radiobut ton.GroupName = "groupname" ; (seen in
http://msdn.microsoft.com/newsgroups...7ec&sloc=en-us)

but this didn't help.

Do you knwo this issue?

Nov 19 '05 #3
Well, it comes out that a constant string
single_radiobut ton.GroupName = "abcdef";
works instead of
single_radiobut ton.GroupName = rbl.ID;

However, sometimes even the datatype 'string' doesn't work but 'int' does
it. So I coded this 'workaround':

string st_rblid = rbl.ID;
single_radiobut ton.GroupName = st_rblid.GetHas hCode().ToStrin g();

And this finally works.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1352
by: Rishi Chandra | last post by:
Reference: http://support.microsoft.com/default.aspx?scid=kb;en- us;316495&Product=aspnet When you add a ASP.NET RadioButton control to the ItemTemplate of a data-bound Repeater server control, the RadioButton control that you created is not mutually exclusive when you run the ASP.NET page. This problem occurs even if the GroupName attribute is set for the RadioButton controls
2
9679
by: Mick | last post by:
Hi, Got a repeater which display question answers and which contains a placeholder. In the ItemDataBound Event, I insert a Radio Button for each answer and set their GroupName with the Question Id. Anyway, when I display my aspx page, I can check ALL radio buttons at same time ! What am I doing wrong?
2
2095
by: dotnettester | last post by:
I have a Web Control Table and I am adding Radio buttons programatically. but when the page is displayed groupname doesn't seem to work. I can select multiple radio buttons.... code snippet... TableRow aRow = new TableRow(); for (int i=0;i<5;i++) { TableCell cell1 = new TableCell(); RadioButton aRadio = new RadioButton();
0
994
by: WO70 | last post by:
Hi, one day I tried to build a WebUserControl with a RadioButton inside. I added 6 of the WebUserControls to my Page and wondered why I was able to select each Radiobutton. I looked at the HTML code and found out, that the Groupname was modified. It was my Groupname with the WebUserControl.ID infront. So I searched and found this: http://support.microsoft.com/default.aspx?scid=kb;en-us;316495
3
1192
by: Iain | last post by:
I have a kind of hierachical templated list class where my templates are set for each datatype that is in the list (well, kind of tree, I suppose). In this case my data wants to be represented by a radio button which is contained in a template. Of course I want all radio buttons at a given level of the tree to be in the same group. This fails because they are each in their own naming container.
3
2535
by: SamSpade | last post by:
FOR WINDOWS FORMS I've been setting all Radio buttons in a group to Checked=False except the clicked one which I set to True. I just noticed the GroupName property and if I understand the doc it will do that for me automatically. Is that correct? I would not post for the above (I could just try). The reason for this post
0
1412
by: Shadow Lynx | last post by:
In standard HTML, the <INPUT type="radio" name="x" /control only allows one radio button to be checked at a time. When more than one are set as checked="true" then only the last one rendered appears as checked. I would assume that asp:RadioButton objects that share the same GroupName would not allow more than one Radio Button to be checked (similar to the Radio Button List) but it seems to not be the case. If I set one Radio Button's...
5
11657
by: Matt B | last post by:
I know this is a bit of nonstandard behavior, but I would like the Enter key to move focus through a group of radiobuttons without selecting them. The user would then have to use Space or actually click to select one of the radiobuttons to select. The default behavior of Focus() seems to also select the radiobutton, but I can't seem to find what is causing this to happen. I would like very much to seperate the Focus and the selection....
5
1613
by: techvaibhav | last post by:
Hello everyone i am stuck in a very annoying problem.Hope you guys help me fix this out. I am displaying questions form a Question database along with its options. Options can be controlled by radiobuttons. The problem is that the group name of all the radiobuttons generated are equal to "question1" therefore i am able to select only one radiobutton of all the buttons that are generated. I should be able to select one radiobutton for every...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.