Validation in TextBox controls in asp.net
-
Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,
Prya
-
Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,
Prya
ASP.NET has validator controls built in, you can define a validation group, a validator for each text field, and messages to show by the textboxes, and in a group in one part of the page. There's a RequiredFieldValidator, a RegularExpressionValidator, and even a CustomValidator, which can be used to run any javascript you like.
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 )
-
ASP.NET has validator controls built in, you can define a validation group, a validator for each text field, and messages to show by the textboxes, and in a group in one part of the page. There's a RequiredFieldValidator, a RegularExpressionValidator, and even a CustomValidator, which can be used to run any javascript you like.
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 )
Thanks a lot for your reply. But, if i use required field validator then, have to use 35-40 that much of validators. sometimes if there is a textbox for more than 100 then also v have to use more than 100 of required field validator. so is there any possiblity in javascript, for validating all the textboxes should not be empty.
Prya
-
Thanks a lot for your reply. But, if i use required field validator then, have to use 35-40 that much of validators. sometimes if there is a textbox for more than 100 then also v have to use more than 100 of required field validator. so is there any possiblity in javascript, for validating all the textboxes should not be empty.
Prya
You can write a custom validator that iterates over all the textboxes, I suppose. But, in the end, given the code that's needed to get a reference to a textbox, it would still be quicker to put the actual validation into a single function, which means you're again better off using the built in stuff. You may be able to recursively iterate over the document looking for textboxes and check if they are empty, but I don't believe it's worthwhile.
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 )
-
Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,
Prya
hi write function in javascript and on form load event add attribute onblur to this function or else on button click u can call js function in which u will check whether any textbox is empty
-
hi write function in javascript and on form load event add attribute onblur to this function or else on button click u can call js function in which u will check whether any textbox is empty
Hi, Thanks. you told that add function in javascript. but we have to specify the name of the textbox in that function know. Then we have to write for every textbox? Can you please explain me. Thanks and Regards,
Prya
-
Hi, Thanks. you told that add function in javascript. but we have to specify the name of the textbox in that function know. Then we have to write for every textbox? Can you please explain me. Thanks and Regards,
Prya
hello Write as in Page_Load()
txt1.Attributes.Add("onblur","javascript:checkValid(this);"); txt2.Attributes.Add("onblur","javascript:checkValid(this);"); ....(write for all textboxes) txt40.Attributes.Add("onblur","javascript:checkValid(this);");
In javascriptfunction checkValid(txtSamp) { if(txtSamp.value =="") alert('Please enter value'); }
Here the function you are calling for all the textboxes is the same,but the arguement differs...'this' keyword refers to the textbox object for which you are calling the function(no need for the name in this function). Hope this helps you ~VSree