读书人

动态生成的控件怎么进行JS进行验证?或

发布时间: 2012-01-26 19:40:46 作者: rapoo

动态生成的控件如何进行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 TextBox();
B[j-1] = new Panel();
B[j-1].Visible = true;


B[j-1].ID = j.ToString();


for (int i = 20; i < A.Length + 20; i++)
{
A[i-20] = new RadioButton();
A[i-20].Text = i.ToString();
A[i-20].Visible = true;
A[i-20].GroupName = j.ToString();
A[i-20].ID = (i*j).ToString();
B[j-1].Controls.Add(A[i-20]);

}
Form1.Controls.Add(txt[j-1]);
Form1.Controls.Add(B[j-1]);
}

}
private void Button1_Click(object sender, System.EventArgs e)
{
for(int i = 1; i < 6; i++)
{
Panel panel = (Panel)this.FindControl(i.ToString());
for(int j = 20;j < 25; j++)
{
RadioButton rad = (RadioButton)panel.FindControl((i*j).ToString());

if(rad.Checked)
{
break;
}
if(!rad.Checked && j ==24)
{
this.Response.Write( " <script> alert( '第 " + i.ToString() + "组没被选 " + " ') </script> ");
}
}

}

}

读书人网 >asp.net

热点推荐