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. Asp.net 2.0 + c#

Asp.net 2.0 + c#

Scheduled Pinned Locked Moved ASP.NET
csharpasp-net
17 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.
  • R Offline
    R Offline
    ritu4321
    wrote on last edited by
    #1

    In my application i have two textboxes and a save button. ON clicking Save button on client side i want to check that the textboxes are not empty and display the appropriate message on the label controls. thanks in advance.

    S S 2 Replies Last reply
    0
    • R ritu4321

      In my application i have two textboxes and a save button. ON clicking Save button on client side i want to check that the textboxes are not empty and display the appropriate message on the label controls. thanks in advance.

      S Offline
      S Offline
      Sylvester george
      wrote on last edited by
      #2

      Use RequiredFieldValidator. Add a RequiredFieldValidator and set the property ControlTovalidate as your textboxname , set the appropriate error message on ErrorMessage property

      Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

      R 1 Reply Last reply
      0
      • S Sylvester george

        Use RequiredFieldValidator. Add a RequiredFieldValidator and set the property ControlTovalidate as your textboxname , set the appropriate error message on ErrorMessage property

        Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

        R Offline
        R Offline
        ritu4321
        wrote on last edited by
        #3

        no i cannot use requiredfieldvalidator . I want to have clint side interaction;requiredfieldvalidator works on server side .Something in javascripting ?????????

        S 1 Reply Last reply
        0
        • R ritu4321

          no i cannot use requiredfieldvalidator . I want to have clint side interaction;requiredfieldvalidator works on server side .Something in javascripting ?????????

          S Offline
          S Offline
          Sylvester george
          wrote on last edited by
          #4

          No buddy. It works in client side. Anyway the javascript code for mandatory text field is here function RequiredField() { document.getElementById("lblErrormessage").innerText = ''; if(document.getElementById("TextBox1").value == '') { document.getElementById("lblErrormessage").innerText = "Field is required"; return false; } return true; } add this method in Page_Load event code bahind on some submit button onclick like button1.Attributes.Add("onclick","return RequiredField()");

          Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

          R 2 Replies Last reply
          0
          • S Sylvester george

            No buddy. It works in client side. Anyway the javascript code for mandatory text field is here function RequiredField() { document.getElementById("lblErrormessage").innerText = ''; if(document.getElementById("TextBox1").value == '') { document.getElementById("lblErrormessage").innerText = "Field is required"; return false; } return true; } add this method in Page_Load event code bahind on some submit button onclick like button1.Attributes.Add("onclick","return RequiredField()");

            Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

            R Offline
            R Offline
            ritu4321
            wrote on last edited by
            #5

            thanks

            C 1 Reply Last reply
            0
            • R ritu4321

              thanks

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Of course, "Textbox1" won't work, as the framework assigns it's own Id, based on where the control is in the page heirarchy. You're definately better off using the validators, which do indeed work on the client.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              1 Reply Last reply
              0
              • S Sylvester george

                No buddy. It works in client side. Anyway the javascript code for mandatory text field is here function RequiredField() { document.getElementById("lblErrormessage").innerText = ''; if(document.getElementById("TextBox1").value == '') { document.getElementById("lblErrormessage").innerText = "Field is required"; return false; } return true; } add this method in Page_Load event code bahind on some submit button onclick like button1.Attributes.Add("onclick","return RequiredField()");

                Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                R Offline
                R Offline
                ritu4321
                wrote on last edited by
                #7

                no i have a problem here . i have two textboxes .The problem is with this . At a time only one label gives text the other is not. i cant understand this . function checknews() { var reqheadline,reqnewsdetail; reqheadline=document.getElementById("TextBox1").innerText; reqnewsdetail=document.getElementById("TextBox2").innerText ; alert(reqnewsdetail); if(reqheadline=="") { document.getElementById("label5").innerText = "Enter Headline" ; return false; } if(reqnewsdetail=="") { alert("bhavna"); document.getElementById("label6").innerText = "Enter News Details" ; return false ; } return true; }

                S 1 Reply Last reply
                0
                • R ritu4321

                  no i have a problem here . i have two textboxes .The problem is with this . At a time only one label gives text the other is not. i cant understand this . function checknews() { var reqheadline,reqnewsdetail; reqheadline=document.getElementById("TextBox1").innerText; reqnewsdetail=document.getElementById("TextBox2").innerText ; alert(reqnewsdetail); if(reqheadline=="") { document.getElementById("label5").innerText = "Enter Headline" ; return false; } if(reqnewsdetail=="") { alert("bhavna"); document.getElementById("label6").innerText = "Enter News Details" ; return false ; } return true; }

                  S Offline
                  S Offline
                  Sylvester george
                  wrote on last edited by
                  #8

                  change like this. if it works give score for me if(reqheadline=="") document.getElementById("label5").innerText = "Enter Headline" ; if(reqnewsdetail=="") document.getElementById("label6").innerText = "Enter News Details" ; if(reqheadline=="" || reqnewsdetail=="") return false ;

                  Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                  R 1 Reply Last reply
                  0
                  • S Sylvester george

                    change like this. if it works give score for me if(reqheadline=="") document.getElementById("label5").innerText = "Enter Headline" ; if(reqnewsdetail=="") document.getElementById("label6").innerText = "Enter News Details" ; if(reqheadline=="" || reqnewsdetail=="") return false ;

                    Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                    R Offline
                    R Offline
                    ritu4321
                    wrote on last edited by
                    #9

                    no its not working . return true does not work now.

                    S 1 Reply Last reply
                    0
                    • R ritu4321

                      no its not working . return true does not work now.

                      S Offline
                      S Offline
                      Sylvester george
                      wrote on last edited by
                      #10

                      add return true; in the end. Why are you not thinking simple logiv I dont know Anyway all the best

                      Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                      R 1 Reply Last reply
                      0
                      • S Sylvester george

                        add return true; in the end. Why are you not thinking simple logiv I dont know Anyway all the best

                        Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                        R Offline
                        R Offline
                        ritu4321
                        wrote on last edited by
                        #11

                        not working var reqheadline,reqnewsdetail; reqheadline=document.getElementById("TextBox1").innerText; reqnewsdetail=document.getElementById("TextBox2").innerText ; if(reqheadline=="") document.getElementById("label5").innerText = "Enter Headline" ; if(reqnewsdetail=="") document.getElementById("label6").innerText = "Enter News Details" ; if(reqheadline=="" || reqnewsdetail=="") return false ; return true; }

                        S 1 Reply Last reply
                        0
                        • R ritu4321

                          not working var reqheadline,reqnewsdetail; reqheadline=document.getElementById("TextBox1").innerText; reqnewsdetail=document.getElementById("TextBox2").innerText ; if(reqheadline=="") document.getElementById("label5").innerText = "Enter Headline" ; if(reqnewsdetail=="") document.getElementById("label6").innerText = "Enter News Details" ; if(reqheadline=="" || reqnewsdetail=="") return false ; return true; }

                          S Offline
                          S Offline
                          Sylvester george
                          wrote on last edited by
                          #12

                          what is the error you are getting?

                          Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                          R 1 Reply Last reply
                          0
                          • S Sylvester george

                            what is the error you are getting?

                            Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                            R Offline
                            R Offline
                            ritu4321
                            wrote on last edited by
                            #13

                            when i fill up now the textboxes it is not getting submitted.

                            S 1 Reply Last reply
                            0
                            • R ritu4321

                              when i fill up now the textboxes it is not getting submitted.

                              S Offline
                              S Offline
                              Sylvester george
                              wrote on last edited by
                              #14

                              why are you changing your code yourself. see my code for text box as if(document.getElementById("TextBox1").value == '') but you changed as innerText. for textbox its value for label its innerText ok

                              Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                              R 1 Reply Last reply
                              0
                              • S Sylvester george

                                why are you changing your code yourself. see my code for text box as if(document.getElementById("TextBox1").value == '') but you changed as innerText. for textbox its value for label its innerText ok

                                Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                                R Offline
                                R Offline
                                ritu4321
                                wrote on last edited by
                                #15

                                sorry for giving you the trouble. now its working . thanks

                                S 1 Reply Last reply
                                0
                                • R ritu4321

                                  sorry for giving you the trouble. now its working . thanks

                                  S Offline
                                  S Offline
                                  Sylvester george
                                  wrote on last edited by
                                  #16

                                  You have to sharpen your Javascript knowledge. Read this link which is from w3cschools.this will help you alot http://www.w3schools.com/js/default.asp[^]

                                  Regards, Sylvester G Senior Software Engineer Xoriant Solutions sylvester_g_m@yahoo.com

                                  1 Reply Last reply
                                  0
                                  • R ritu4321

                                    In my application i have two textboxes and a save button. ON clicking Save button on client side i want to check that the textboxes are not empty and display the appropriate message on the label controls. thanks in advance.

                                    S Offline
                                    S Offline
                                    shirish78
                                    wrote on last edited by
                                    #17

                                    You can either use javascript or requiredfield validatior for this

                                    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