473,378 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_item in rbl_values.Rows)
{
RadioButton single_radiobutton = new RadioButton();
single_radiobutton.ID = "idname";
single_radiobutton.GroupName = "groupname";
this.Page.Controls.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_radiobutton.Attributes.Add("name", mygroupname) instead of
single_radiobutton.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 3043
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_item in rbl_values.Rows)
{
RadioButton single_radiobutton = new RadioButton();
single_radiobutton.ID = "idname";
single_radiobutton.GroupName = "groupname";
this.Page.Controls.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_radiobutton.Attributes.Add("name", mygroupname) instead of
single_radiobutton.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_radiobutton.GroupName
= rbl.ID;" in the ascx-file "inputRadiobuttonlist.ascx" is not commented out)
and I take the following steps:
1) choose none of the radios
2) hit "submit"
--> button-method "Button1_Click" (from "default.aspx") is called correctly
(displays <DateTime.Now>)
3) choose one of the radios (only one possible)
4) hit "submit"
--> button-method "Button1_Click" (from "default.aspx") 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_radiobutton.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.aspx" contains the following placeholder and button:

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

File "Default.aspx.cs":

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Control c = (Control)this.LoadControl("inputRadiobuttonlist.as cx");

this.ph.Controls.Add(c);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("button method called "+
DateTime.Now.ToLongTimeString());
}
}

File "inputRadiobuttonlist.ascx":

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="inputRadiobuttonlist.ascx.cs" Inherits="inputRadiobuttonlist" %>
<tr><td colspan=3><asp:Label ID="rbl_text" runat="server"
Text="Label"></asp:Label>
<asp:CustomValidator ID="valid_rbl" runat="server"
ErrorMessage="CustomValidator"
EnableClientScript="False"></asp:CustomValidator></td>
</tr>
<tr><td colspan=3><asp:Table ID="rbl" runat="server">
</asp:Table></td></tr>

File "inputRadiobuttonlist.ascx.cs":

public partial class inputRadiobuttonlist : System.Web.UI.UserControl
{
private const string mandatory = "mandatory";

protected void Page_Load(object sender, EventArgs e)
{
this.rbl_text.ID = "snippetid";
this.rbl_text.Text = "snippet_text";
this.rbl.ID = "radiobuttons";

if (mandatory.IndexOf("mandatory") != -1)
{
this.rbl_text.Text += "*";

}

//just to have some radiobbutons to add
DataTable rbl_values = new DataTable();
rbl_values.Columns.Add("choice_text");
rbl_values.Columns.Add("choice_value");
DataRow first_row = rbl_values.NewRow();
first_row["choice_text"] = "yes";
first_row["choice_value"] = "y";
rbl_values.Rows.Add(first_row);
DataRow scnd_row = rbl_values.NewRow();
scnd_row["choice_text"] = "no";
scnd_row["choice_value"] = "n";
rbl_values.Rows.Add(scnd_row);
//adding the radiobuttons dynamically
TableRow single_row = new TableRow();
foreach (DataRow radiobutton_item in rbl_values.Rows)
{

TableCell single_cell0 = new TableCell();

RadioButton single_radiobutton = new RadioButton();

string radiobutton_id =
radiobutton_item["choice_value"].ToString();
single_radiobutton.ID = radiobutton_id;
//single_radiobutton.Attributes.Add("name", rbl.ID);
single_radiobutton.GroupName = rbl.ID;

single_cell0.Controls.Add(single_radiobutton);
single_row.Cells.Add(single_cell0);

TableCell single_cell1 = new TableCell();

Label radiobutton_text = new Label();
radiobutton_text.Text =
radiobutton_item["choice_text"].ToString();

single_cell1.Controls.Add(radiobutton_text);
single_row.Cells.Add(single_cell1);

}

rbl.Controls.Add(single_row);

this.rbl_text.ForeColor = 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_item in rbl_values.Rows)
{
RadioButton single_radiobutton = new RadioButton();
single_radiobutton.ID = "idname";
single_radiobutton.GroupName = "groupname";
this.Page.Controls.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_radiobutton.Attributes.Add("name", mygroupname) instead of
single_radiobutton.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_radiobutton.GroupName = "abcdef";
works instead of
single_radiobutton.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_radiobutton.GroupName = st_rblid.GetHashCode().ToString();

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
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,...
2
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...
2
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......
0
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...
3
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...
3
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...
0
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...
5
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.