Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have 4 server control textboxes and a sumbit asp button before hitting it in server how can i check whether the asp textboxes are filled properly or not if and only if it is filled properly the value has to be passed in server
please help
thanks in advance
Posted

ASP.Net has validation controls that you should see on your ToolBox. There are some for validating nummbers, dates, RegEx, Required, etc. Or, you can always use JS. I would start with the validation controls on the toolbox and then come back if you run into problems.
 
Share this answer
 
Comments
Oshtri Deka 29-Feb-12 16:41pm    
I agree. Use validators and if they don't suit you, use JavaScript.
5.
It is better to use client side validation of text box.
 
Share this answer
 
Comments
ZurdoDev 29-Feb-12 16:44pm    
To be clear, you always want to validate both client side and server side. Client side can easily be hacked by someone who has the right tools.
function validate()
{
 var txt1=document.getElementById("<%=txtBox1.ClientID%>");
 if(txt1.value=="")
{
return false;

}
 }

call this function using Button OnClientClick="return validate();"
 
Share this answer
 
you can use validation controls of asp.net but the best u wil use javascript for client side validation,use following js function to validate textbox 'onClientclick'event of asp button
JavaScript
function()
{
if (document.getElementById('txt_toId').value == '') {
     alert('Please Enter To Code!');
      document.getElementById('txt_toId').focus();
       return false;
                }
                else {
                    return true;
                }
}
 
Share this answer
 
try this javascript...
XML
<script language="javascript" type="text/javascript">
        function ValidateSaveRegion() {

            var Date = document.getElementById('cntPlcHolder_txtDate');

C#
if (Date.value.match(/^\s+$/) || Date.value == "") {

                alert('Enter Date');
                Date.focus();
                return false;
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900