日期:2014-05-19  浏览次数:20380 次

动态生成的控件如何进行JS进行验证??或者是程序本身验证亦可!
问题是这样的...我动态生成了N组RadioButton,且每一组都有一个TextBox(也是动态生成的)....

现在问题是这样,在提交之前,我想验证其中一组是否已经有checked==true,如果没有选中,则提示...如果该组的TextBox是onFocus的话,那么TextBox所在的那一组的RadioRutton如果已经有选中的话,就取消...

我这样说,明白吧...请高手帮帮忙!分不多了....

Panel[]   B   =   new   Panel[5];
                RadioButton[]   A   =   new   RadioButton[5];

                TextBox[]   txt   =   new   TextBox[5]
                for   (int   j   =   0;   j   <   B.Length;   j++)
                {
                        txt[j]=   new   TextBox();
                        B[j]   =   new   Panel();
                        B[j].Visible   =   true;
                        B[j].ID   =   j.ToString();
                        B[j].Attributes.Add( "question ",   j.ToString());
                        for   (int   i   =   0;   i   <   A.Length;   i++)
                        {
                                A[i]   =   new   RadioButton();
                                A[i].Text   =   i.ToString();
                                A[i].Visible   =   true;
                                A[i].GroupName   =   j.ToString();
                             
                             

                                B[j].Controls.Add(A[i]);
                       
                        }
                        PH1.Controls.Add(txt[j]);
                        PH1.Controls.Add(B[j]);

------解决方案--------------------
写了一个判断哪组的RadioButton没被选种的代码 参考下 页面放了一个服务器的button1

private void Page_Load(object sender, System.EventArgs e)
{
BD();
}
private void BD()
{
Panel[] B = new Panel[5];
RadioButton[] A = new RadioButton[5];

TextBox[] txt = new TextBox[5];

for (int j = 1; j < B.Length + 1; j++)
{
txt[j-1]= new TextBo