0
 <script type="text/javascript">
    var msg;
    function req1(form)
    {

    if (form.textbox1.value == "" || form.textbox2.value == "")
    {   
       msg= "Please Enter Username And Password";
       return false; 
    }
    else
    {
         return true;
    }

}

    </script>

This is my javascript and i want to use it in asp.net form..so hw can i saw error msg in defalt.aspx page...or hw can i use return value(like true or false)in asp.net

4 Answers 4

3

You could use a requiredfieldvalidator for both textbox1 and textbox2 or if you need to validate them at the same time you can use a customvalidator and hookup your clientside javascript like done here: http://www.geekzilla.co.uk/ViewD27B15B4-71A4-4258-81EE-9445FAA9F634.htm

if you need to hard reference your serverside textboxes make sure you use <%= textbox1.ClientID %> in your javascript.

Sign up to request clarification or add additional context in comments.

Comments

3

ASP.NET provides the CustomValidator control with which you can validate multiple controls on the client and serverside with custom validation logic.

Take a look at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction.aspx for a small example.

Comments

1

thnkx i gt solution frm another user...

function vali() { if (document.getElementById("").value == "") { var m = document.getElementById(""); m.innerHTML= "Please Enter the Name First"; return false; } else m = document.getElementById(""); m.innerHTML=""; return true; }

<asp:Label ID="L1" runat="server" Text="Name"/>
<br />
<br />
<asp:TextBox ID="T1" runat="server" />
<br/>
<br/>


<asp:Button ID="B1" runat="server" OnClientClick="return vali()" />
<br/>



</div>
</form>

Comments

0

in the submit button add this attribute

onclientclick="req1(document.form[0])"

This will call the clientside javascript before submitting to the server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.