Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Friday, February 03, 2012

Another way to write JavaScript Validaton for Server Controls in SharePoint

<script language="javascript" type="text/javascript">
    function validateControls()
    {

        if (document.getElementById("<%=txtUserName.ClientID %>").value == "")
        {
            alert('UserName Required');
            document.getElementById("<%=txtUserName.ClientID %>").focus();
            return false;
        }

        if (document.getElementById("<%=txtPassWord.ClientID %>").value == "")
        {
            alert('PassWord Required');
            document.getElementById("<%=txtPassWord.ClientID %>").focus();
            return false;
        }
        return true;
    }
</script>

In Page_Load of UserControl use the button properties in this way.
 btnSave.Attributes.Add("OnClick", "return validateControls();");

No comments:

Post a Comment