本文介绍了用于Web表单动态控件的asp验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建webform和验证的动态控件但是那些没有激活我保持验证组的静态按钮,这里需要验证是我的代码







开关(dr [DATATYPE]。ToString())

{

caseint :

casestring:

TextBox tb = new TextBox();

tb.ID = dr [FIELDNAME]。ToString ();

td1.Controls.Add(tb);

if(flag ==show)

tb.Text = _frmElement .Element(dr [FIELDNAME]。ToString())。Value;

else if(flag ==new)

tb.Text =;







// ---验证



if(dr [ISMANDATORY]。ToString()!=(1).ToString())

{

RequiredFieldValidator rq = new RequiredFieldValidator();

rq.ControlToValidate = tb.ID;

rq.ErrorMessage =这些字段是必需的;

rq。 ValidationGroup =a;

}



// - 验证

休息;

< asp:button id =Btnsaverunat =servervalidationgroup =a>





为什么我不能做验证

I'm creating dynamic controls of webform and also validations but those were not firing i kept validation group for a static button and required validation here is my code



switch (dr["DATATYPE"].ToString())
{
case "int":
case "string":
TextBox tb = new TextBox();
tb.ID = dr["FIELDNAME"].ToString();
td1.Controls.Add(tb);
if(flag=="show")
tb.Text = _frmElement.Element(dr["FIELDNAME"].ToString()).Value;
else if (flag == "new")
tb.Text = "";



//--- validations

if (dr["ISMANDATORY"].ToString() != (1).ToString())
{
RequiredFieldValidator rq = new RequiredFieldValidator();
rq.ControlToValidate = tb.ID;
rq.ErrorMessage = "This fields are required";
rq.ValidationGroup = "a";
}

//--validations
break;
<asp: button id="Btnsave" runat="server" validationgroup="a">


Why so im not able to do validations

推荐答案

这篇关于用于Web表单动态控件的asp验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:10