如何从code dislay验证消息的背后 [英] How to dislay Validation Message from code behind
问题描述
我有一个文本框..
我想验证它是一个基于DropDownList的值值..
所以我从code显示的讯息后面使用 RegularEx pressionValidator
..
但它不工作PLZ,给我的建议。
< ASP:文本框ID =tbnooflecture=服务器WIDTH =119pxHEIGHT =33px>< / ASP:文本框> < ASP:RegularEx pressionValidator ID =RegularEx pressionValidator1前景色=#6600FF
=服务器的ValidationGroup =上
的ControlToValidate =tbnooflecture>< / ASP:RegularEx pressionValidator>
< ASP:按钮的ID =bfillattendence=服务器文本=,填补考勤点击这里
的onclick =FillAttendence_ClickWIDTH =218pxHEIGHT =33px的CausesValidation =真的ValidationGroup =上/>
我写低于code在按钮的Click事件
字符串batchname = dpbatchname.SelectedItem.Text.ToString();
INT lengthofbatch = batchname.Length;
如果(lengthofbatch == 2)
{
RegularEx pressionValidator1.ValidationEx pression =[1-9] [02468] | [02468]; RegularEx pressionValidator1.ErrorMessage =只有连考勤号是实验室有效。
}
否则如果(lengthofbatch == 1)
{
RegularEx pressionValidator1.ValidationEx pression =[0-9] [0-9] | [0-9];
RegularEx pressionValidator1.ErrorMessage =考勤应和9,50一样;
}
其他
{
RegularEx pressionValidator1.ValidationEx pression =[0-9] [0-9] | [0-9];
RegularEx pressionValidator1.ErrorMessage =考勤应和9,50一样;
}
添加此行
RequiredFieldValidator1.IsValid = FALSE;
在
RegularEx pressionValidator1.ValidationEx pression =[0-9] [0-9] | [0-9];
RegularEx pressionValidator1.ErrorMessage =考勤应和9,50一样;
I have one textbox..
i want to validate it's value based on dropdownlist value..
So i am displaying message from code behind using RegularExpressionValidator
..
But it is not working plz,give me suggestion..
<asp:TextBox ID="tbnooflecture" runat="server" Width="119px" Height="33px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ForeColor="#6600FF"
runat="server" ValidationGroup="upper"
ControlToValidate="tbnooflecture"></asp:RegularExpressionValidator>
<asp:Button ID="bfillattendence" runat="server" Text="To Fill Attendence Click Here"
onclick="FillAttendence_Click" Width="218px" Height="33px" CausesValidation="true" ValidationGroup="upper"/>
i am writing below code in Button click event
string batchname = dpbatchname.SelectedItem.Text.ToString();
int lengthofbatch=batchname.Length;
if(lengthofbatch==2)
{
RegularExpressionValidator1.ValidationExpression = "[1-9][02468]|[02468]";
RegularExpressionValidator1.ErrorMessage = "Only Even No. of Attendence is Valid for Lab.";
}
else if (lengthofbatch == 1)
{
RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
}
else
{
RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
}
Add this line RequiredFieldValidator1.IsValid = false;
after
RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]"; RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
这篇关于如何从code dislay验证消息的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!