我正在使用asp.net web表单,我正在使用CustomValidator
与服务器端验证事件OnServerValidate
来验证页面的某些内容
并使用ajax AsyncFileUpload
控件上传文件。
两个控件CustomValidator
和AsyncFileUpload
在页面上是独立的,两者之间没有关系,但当我在AsyncFileUpload
中选择任何文件时,CustomValidator的服务器端验证事件会自动触发哪个造成问题。自定义验证器验证方法只应在我单击相应的提交按钮时触发,该按钮工作正常但另外CustomValidator
OnServerValidate
方法也会AsyncFileUpload
触发文件选择。
fallowing是我为展示问题而创建的示例代码。
ASPX代码
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<%-- <asp:UpdatePanel ID="upUpdateSplitedExposure" runat="server" UpdateMode="Conditional">
<ContentTemplate>--%>
<asp:CustomValidator ID="cvValidateSplitExposureSumByServer" Display="None"
runat="server" ErrorMessage="" OnServerValidate="cvValidateSplitExposureSumByServer_ValidateSplitExposureSum" ControlToValidate="txttmpValidateSum" ValidateEmptyText="true"
ValidationGroup="UpdateExposure"></asp:CustomValidator>
<asp:TextBox runat="server" ID="txttmpValidateSum" Style="display: none; width: 0px" ValidationGroup="UpdateExposure"></asp:TextBox>
<asp:Button ID="imgBtnUpdateSplitedExposure" runat="server" ToolTip="OK"
Text="OK" CausesValidation="true" ValidationGroup="UpdateExposure" Enabled="true" />
<%-- </ContentTemplate>
</asp:UpdatePanel>--%>
<%-- <asp:UpdatePanel ID="upUploadPayRoll" runat="server" UpdateMode="Always">
<ContentTemplate>--%>
<asp:AsyncFileUpload ID="asyncPayRollUploader" runat="server" CompleteBackColor="White"
Width="400px" EnableViewState="false" />
<asp:Button ID="ImageButton1" runat="server" ToolTip="OK"
Text="OK" CausesValidation="true" ValidationGroup="NEWG" Enabled="true" />
<%-- </ContentTemplate>
</asp:UpdatePanel>--%>
</div>
</form>
VB
Partial Class AsyncUpload
Inherits System.Web.UI.Page
Protected Sub cvValidateSplitExposureSumByServer_ValidateSplitExposureSum(source As Object, args As ServerValidateEventArgs)
Try
args.IsValid = False
Catch ex As Exception
args.IsValid = False
End Try
End Sub
Protected Sub asyncPayRollUploader_UploadedComplete(sender As Object, e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles asyncPayRollUploader.UploadedComplete
End Sub
Protected Sub ImageButton1_Click(sender As Object, e As EventArgs) Handles ImageButton1.Click
End Sub
Protected Sub imgBtnUpdateSplitedExposure_Click(sender As Object, e As EventArgs) Handles imgBtnUpdateSplitedExposure.Click
End Sub
End Class
任何人都可以帮助我吗?