Why the Custom Validation is firing wrongly
-
I have two FileUpload button in my form which I put two custom validators. The issue is, when I click on first upload button, the second one also fires and says that it is required field or the similar message. Any idea what is going on? I need to fire only those custom validator belonging to that particualr control. Here is the code:
<asp:FileUpload ID="MPNCPNFileUpload" runat="server" />
<asp:Button ID="MPNCPNFileUploadButton" runat="server" OnClick="TabFileUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="TabFileUploadErrorCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="TabFileUploadedCustomValidator_ServerValidate">TextFile with MPN-CPN Details should
be uploaded</asp:CustomValidator><asp:FileUpload ID="DocumentFileUpload" runat="server" />
<asp:Button ID="DocumentUploadButton" runat="server" OnClick="DocumentUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="DocumentUploadedCustomValidator_ServerValidate">Document
must be uploaded</asp:CustomValidator>protected void TabFileUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["PartsDetailFileName"]));}
protected void DocumentUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["DocumentFileId"]));
}pls help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
I have two FileUpload button in my form which I put two custom validators. The issue is, when I click on first upload button, the second one also fires and says that it is required field or the similar message. Any idea what is going on? I need to fire only those custom validator belonging to that particualr control. Here is the code:
<asp:FileUpload ID="MPNCPNFileUpload" runat="server" />
<asp:Button ID="MPNCPNFileUploadButton" runat="server" OnClick="TabFileUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="TabFileUploadErrorCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="TabFileUploadedCustomValidator_ServerValidate">TextFile with MPN-CPN Details should
be uploaded</asp:CustomValidator><asp:FileUpload ID="DocumentFileUpload" runat="server" />
<asp:Button ID="DocumentUploadButton" runat="server" OnClick="DocumentUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="DocumentUploadedCustomValidator_ServerValidate">Document
must be uploaded</asp:CustomValidator>protected void TabFileUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["PartsDetailFileName"]));}
protected void DocumentUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["DocumentFileId"]));
}pls help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
Hi meeram395, Validation groups might solve your problem. So if you change the first button and the custom validator like so:
and then for the second button and custom validator:
asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic" ErrorMessage="CustomValidator" OnServerValidate="DocumentUploadedCustomValidator_ServerValidate" ValidationGroup="ValGroup2">
So the first button will only validate ValGroup1 and the second button will only validate ValGroup2. I hope this helps. Ryan
-
Hi meeram395, Validation groups might solve your problem. So if you change the first button and the custom validator like so:
and then for the second button and custom validator:
asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic" ErrorMessage="CustomValidator" OnServerValidate="DocumentUploadedCustomValidator_ServerValidate" ValidationGroup="ValGroup2">
So the first button will only validate ValGroup1 and the second button will only validate ValGroup2. I hope this helps. Ryan
-
So I need to make modification only in aspx page? There is no change in the code-behind? I mean no change in ServerValidate event?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
No, you shouldn't need to change the code-behind.
-
I have two FileUpload button in my form which I put two custom validators. The issue is, when I click on first upload button, the second one also fires and says that it is required field or the similar message. Any idea what is going on? I need to fire only those custom validator belonging to that particualr control. Here is the code:
<asp:FileUpload ID="MPNCPNFileUpload" runat="server" />
<asp:Button ID="MPNCPNFileUploadButton" runat="server" OnClick="TabFileUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="TabFileUploadErrorCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="TabFileUploadedCustomValidator_ServerValidate">TextFile with MPN-CPN Details should
be uploaded</asp:CustomValidator><asp:FileUpload ID="DocumentFileUpload" runat="server" />
<asp:Button ID="DocumentUploadButton" runat="server" OnClick="DocumentUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="DocumentUploadedCustomValidator_ServerValidate">Document
must be uploaded</asp:CustomValidator>protected void TabFileUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["PartsDetailFileName"]));}
protected void DocumentUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["DocumentFileId"]));
}pls help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
To solve this issue, you can set "ValidationGroup" property of each control. Try to set MPNCPNFileUpload, MPNCPNFileUploadButton and TabFileUploadErrorCustomValidator controls "ValidationGroup" property to "2" and DocumentFileUpload, DocumentUploadButton and DocumentUploadedCustomValidator controls "ValidationGroup" property to "3". hope this will help you. :cool: Regards... Vijay Jain
-
I have two FileUpload button in my form which I put two custom validators. The issue is, when I click on first upload button, the second one also fires and says that it is required field or the similar message. Any idea what is going on? I need to fire only those custom validator belonging to that particualr control. Here is the code:
<asp:FileUpload ID="MPNCPNFileUpload" runat="server" />
<asp:Button ID="MPNCPNFileUploadButton" runat="server" OnClick="TabFileUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="TabFileUploadErrorCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="TabFileUploadedCustomValidator_ServerValidate">TextFile with MPN-CPN Details should
be uploaded</asp:CustomValidator><asp:FileUpload ID="DocumentFileUpload" runat="server" />
<asp:Button ID="DocumentUploadButton" runat="server" OnClick="DocumentUploadButton_Click"
Text="Upload" /></td></tr>
<tr><td><asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic"
ErrorMessage="CustomValidator"
OnServerValidate="DocumentUploadedCustomValidator_ServerValidate">Document
must be uploaded</asp:CustomValidator>protected void TabFileUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["PartsDetailFileName"]));}
protected void DocumentUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["DocumentFileId"]));
}pls help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
There is a Property called ValidationGroup. Using this property should solve your problem. Below is a sample: TextFile with MPN-CPN Details should be uploaded
-
To solve this issue, you can set "ValidationGroup" property of each control. Try to set MPNCPNFileUpload, MPNCPNFileUploadButton and TabFileUploadErrorCustomValidator controls "ValidationGroup" property to "2" and DocumentFileUpload, DocumentUploadButton and DocumentUploadedCustomValidator controls "ValidationGroup" property to "3". hope this will help you. :cool: Regards... Vijay Jain
-
No, you shouldn't need to change the code-behind.