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. CompreValidator for Textbox and FileUpload

CompreValidator for Textbox and FileUpload

Scheduled Pinned Locked Moved ASP.NET
9 Posts 2 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.
  • A Offline
    A Offline
    anada8886
    wrote on last edited by
    #1

    I have to validate 1 textbox and 1 FileUpload control on my page. I have make the user to fill at least one of them, i.e. both of them can not be left blank. Do anybody have any idea about how can use the CompareValidator for this. Thank you.

    S 1 Reply Last reply
    0
    • A anada8886

      I have to validate 1 textbox and 1 FileUpload control on my page. I have make the user to fill at least one of them, i.e. both of them can not be left blank. Do anybody have any idea about how can use the CompareValidator for this. Thank you.

      S Offline
      S Offline
      sashidhar
      wrote on last edited by
      #2

      anada8886 wrote:

      I have to validate 1 textbox and 1 FileUpload control on my page

      Use customvalidator and javascript function..! or use server side validation..!

      anada8886 wrote:

      can use the CompareValidator for this.

      why would you go for compare validator..! Is it manadatory..?:confused:

      LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

      A 1 Reply Last reply
      0
      • S sashidhar

        anada8886 wrote:

        I have to validate 1 textbox and 1 FileUpload control on my page

        Use customvalidator and javascript function..! or use server side validation..!

        anada8886 wrote:

        can use the CompareValidator for this.

        why would you go for compare validator..! Is it manadatory..?:confused:

        LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

        A Offline
        A Offline
        anada8886
        wrote on last edited by
        #3

        Thanks for the reply. I have already tried using Custom validator with Javascript but it is giving me some JS error. And it is giving that error only for Custom validator,that is why I thought if it can be done using CompareValidator. Secondly ,I want it in client side only,it should not go to server side.

        S 1 Reply Last reply
        0
        • A anada8886

          Thanks for the reply. I have already tried using Custom validator with Javascript but it is giving me some JS error. And it is giving that error only for Custom validator,that is why I thought if it can be done using CompareValidator. Secondly ,I want it in client side only,it should not go to server side.

          S Offline
          S Offline
          sashidhar
          wrote on last edited by
          #4

          anada8886 wrote:

          I thought if it can be done using CompareValidator.

          the answer is no ..!You cant do it with comparevalidator..! the compare validator checks if both the values are identical or not ..! thts it..!

          <script language ="javascript" type ="text/javascript" >
          function CheckEmpty() {
          var fromaddress = document.getElementById('<%= TextBox1.ClientID %>').value;
          var fromaddress1 = document.getElementById('<%= FileUpload1.ClientID %>').value;
          if (fromaddress=="" && fromaddress1=="") {

                  alert("Should not be empty");
              }
          
          }
          
          </script>
          <div>
          

          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          <asp:FileUpload ID="FileUpload1" runat="server" />
          <asp:CustomValidator ID="CustomValidator1" runat="server"
          ErrorMessage="should not be blank..!"
          ClientValidationFunction="CheckEmpty"></asp:CustomValidator>

          </div>
          <asp:Button ID="Button1" runat="server" Text="Button" />
          </form>
          

          LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

          A 1 Reply Last reply
          0
          • S sashidhar

            anada8886 wrote:

            I thought if it can be done using CompareValidator.

            the answer is no ..!You cant do it with comparevalidator..! the compare validator checks if both the values are identical or not ..! thts it..!

            <script language ="javascript" type ="text/javascript" >
            function CheckEmpty() {
            var fromaddress = document.getElementById('<%= TextBox1.ClientID %>').value;
            var fromaddress1 = document.getElementById('<%= FileUpload1.ClientID %>').value;
            if (fromaddress=="" && fromaddress1=="") {

                    alert("Should not be empty");
                }
            
            }
            
            </script>
            <div>
            

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:CustomValidator ID="CustomValidator1" runat="server"
            ErrorMessage="should not be blank..!"
            ClientValidationFunction="CheckEmpty"></asp:CustomValidator>

            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            </form>
            

            LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

            A Offline
            A Offline
            anada8886
            wrote on last edited by
            #5

            Thanks for your reply sir, but as I told you using CustomValidator is giving me error - 'Microsoft JScript runtime error: Object required',in the method WebForm_RemoveClassName(element, className) of WebResource.axd.

            S 1 Reply Last reply
            0
            • A anada8886

              Thanks for your reply sir, but as I told you using CustomValidator is giving me error - 'Microsoft JScript runtime error: Object required',in the method WebForm_RemoveClassName(element, className) of WebResource.axd.

              S Offline
              S Offline
              sashidhar
              wrote on last edited by
              #6

              anada8886 wrote:

              Thanks for your reply sir

              You no need to call any one as sir in here. ..! then remove the custom validator..!and add the function for button click client validation..! as shown below..! Check OnClientClick="CheckEmpty();"

              <asp:Button ID="Button1" runat="server" OnClientClick="CheckEmpty();" Text="Button" />

              LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

              A 1 Reply Last reply
              0
              • S sashidhar

                anada8886 wrote:

                Thanks for your reply sir

                You no need to call any one as sir in here. ..! then remove the custom validator..!and add the function for button click client validation..! as shown below..! Check OnClientClick="CheckEmpty();"

                <asp:Button ID="Button1" runat="server" OnClientClick="CheckEmpty();" Text="Button" />

                LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                A Offline
                A Offline
                anada8886
                wrote on last edited by
                #7

                Hey thanks, it worked !!!

                S 1 Reply Last reply
                0
                • A anada8886

                  Hey thanks, it worked !!!

                  S Offline
                  S Offline
                  sashidhar
                  wrote on last edited by
                  #8

                  anada8886 wrote:

                  Hey thanks, it worked !!!

                  Any Time..!:thumbsup: Here it is a tradition to mark it as answer if it helps..!

                  LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                  A 1 Reply Last reply
                  0
                  • S sashidhar

                    anada8886 wrote:

                    Hey thanks, it worked !!!

                    Any Time..!:thumbsup: Here it is a tradition to mark it as answer if it helps..!

                    LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.

                    A Offline
                    A Offline
                    anada8886
                    wrote on last edited by
                    #9

                    Yes ,I know but I couldn't find any way here to mark your comment as 'Answer'.

                    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