CustomValidator "OnServerValidate" event automatically firing when file selected through AsyncFileUpload control

583 views Asked by At

I am working on asp.net web form where I am using CustomValidator with server side validation event OnServerValidate to validate some stuff of page and also using ajax AsyncFileUpload control to upload the file.

the both controls CustomValidator and AsyncFileUpload are independent on page there are no relation between both, but when I select any file in AsyncFileUpload the server side validation event of CustomValidator automatically firing which causing issue. the custom validator validation method should only fire when I click on their respective submit button which is working correctly but in addition CustomValidator OnServerValidate method also firing by AsyncFileUpload on file selection.

fallowing is the sample code I have created to demonstrate the issue.

ASPX Code

<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

Can any one help me please?

0

There are 0 answers