我有一个文本框..我想根据下拉列表值验证它的值..所以我正在使用后面的代码显示消息RegularExpressionValidator
..但它不起作用请给我建议..
<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"/>
我在按钮点击事件中写下面的代码
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";
}