服务器端验证不起作用? [英] server side validation does not work?
本文介绍了服务器端验证不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:TextBox ID = txttodt runat = server BorderColor = #8F7591 BorderWidth = 1px CssClass = txtinput BorderStyle = 实体 BackColor = #F4F4F4 onkeyup = KeyRemover(this) onpaste = 返回false > < / asp:TextBox >
< asp:CustomValidator id < span class =code-keyword> = cvtxttodt runat = server ControlToValidate = < span class =code-keyword> txttodt OnServerValidate = Validatetxttodt CssClass = < span class =code-keyword> Validation_Error ErrorMessage = 输入日期 ForeColor = WhiteSmoke ValidationGroup = NTST / >
< asp:按钮 ID = btnprtNTST runat = server < span class =code-attribute>宽度 = 80px 字体粗体 = true 文字 = 提交 ValidationGroup = NTST CssClass = button < span class =code-attribute> / >
Sub Validatetxttodt( ByVal 发件人作为 对象, ByVal args As ServerValidateEventArgs)
尝试
如果(txttodt.Text = )然后
args.IsValid = False
否则
args.IsValid = True
结束 如果
Catch ex As 例外
args.IsValid = 错误
结束 尝试
结束 Sub
不工作?控制在调试时没有捕获sub?
解决方案
hi,
设置属性ValidateEmptyText = true
txttodt.Text
的价值是多少?
你只测试一下等于String.Empty
。但是如果txttodt.Text
是Nothing
怎么办?
更好的方法是:
Sub Validatetxttodt( ByVal sender 作为 对象, ByVal args As ServerValidateEventArgs)
尝试
如果( String .IsNullOrEmpty(txttodt.Text))然后
args.IsValid = 错误
其他
args.IsValid = True
结束 如果
Catch ex 作为例外
args.IsValid = 错误
结束 尝试
结束 Sub
但它没有解决Sub
未执行的问题...
<asp:TextBox ID="txttodt" runat="server" BorderColor="#8F7591" BorderWidth="1px" CssClass="txtinput" BorderStyle="Solid" BackColor="#F4F4F4" onkeyup="KeyRemover(this)" onpaste="return false"></asp:TextBox>
<asp:CustomValidator id="cvtxttodt" runat="server" ControlToValidate="txttodt" OnServerValidate ="Validatetxttodt" CssClass="Validation_Error" ErrorMessage="enter date" ForeColor="WhiteSmoke" ValidationGroup="NTST" />
<asp:Button ID="btnprtNTST" runat="server" Width="80px" Font-Bold="true" Text="Submit" ValidationGroup="NTST" CssClass="button" />
Sub Validatetxttodt(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
Try
If (txttodt.Text = "") Then
args.IsValid = False
Else
args.IsValid = True
End If
Catch ex As Exception
args.IsValid = False
End Try
End Sub
not working ? control does not catch sub at debug time?
解决方案
hi,
Set propertyValidateEmptyText="true"for custom validator
What is the value oftxttodt.Text
?
You only test for equality toString.Empty
. But what iftxttodt.Text
isNothing
?
A better way would be :
Sub Validatetxttodt(ByVal sender As Object, ByVal args As ServerValidateEventArgs) Try If (String.IsNullOrEmpty(txttodt.Text)) Then args.IsValid = False Else args.IsValid = True End If Catch ex As Exception args.IsValid = False End Try End Sub
But it doesn''t solve the problem of theSub
not being executed...
这篇关于服务器端验证不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文