<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();");
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