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?