Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Why the Custom Validation is firing wrongly

Why the Custom Validation is firing wrongly

Scheduled Pinned Locked Moved ASP.NET
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meeram395
    wrote on last edited by
    #1

    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.

    R J H 3 Replies Last reply
    0
    • M meeram395

      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.

      R Offline
      R Offline
      RyanMorris
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • R RyanMorris

        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

        M Offline
        M Offline
        meeram395
        wrote on last edited by
        #3

        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.

        R 1 Reply Last reply
        0
        • M meeram395

          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.

          R Offline
          R Offline
          RyanMorris
          wrote on last edited by
          #4

          No, you shouldn't need to change the code-behind.

          M 1 Reply Last reply
          0
          • M meeram395

            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.

            J Offline
            J Offline
            Jain Vijay
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • M meeram395

              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.

              H Offline
              H Offline
              Hajab
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • H Hajab

                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

                M Offline
                M Offline
                meeram395
                wrote on last edited by
                #7

                Thanks to everyboyd. It got worked.. Thanks again.

                Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

                1 Reply Last reply
                0
                • J Jain Vijay

                  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

                  M Offline
                  M Offline
                  meeram395
                  wrote on last edited by
                  #8

                  Thanks very much. It worked.

                  Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

                  1 Reply Last reply
                  0
                  • R RyanMorris

                    No, you shouldn't need to change the code-behind.

                    M Offline
                    M Offline
                    meeram395
                    wrote on last edited by
                    #9

                    Sorry for the late reply. It worked. Thank you very much.

                    Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups