I was creating a registration form and I have a doubt here:
What is a best practice at the moment of clicking the button register... check all the input text using javascript or a method including at the code behind and being called on click event...it's a silly question but I'm newbie developing applications with ASP.NET
Loading

sudharsan sPosted Jun 18, 2012, 1:25 AM
function validate()
{
if (document.getElementById("<%=dropcategory.ClientID%>").value == "===Select Category===")
{
alert("(*)Select Category TO Upload the File");
document.getElementById("<%=dropcategory.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=DropDownList1.ClientID %>").value == "===Select SubCategory===")
{
alert("(*)Select SubCategory TO Upload the File");
document.getElementById("<%=DropDownList1.ClientID %>").focus();
return false;
}
if (document.getElementById("<%=txtOwnerId.ClientID %>").value == "===Select Owner ID===") {
alert("(*)Select OwnerID TO Upload the File");
document.getElementById("<%=txtOwnerId.ClientID %>").focus();
return false;
}
if (document.getElementById("<%=demo1.ClientID %>").value == "") {
alert("(*)Select Date Upload the File");
document.getElementById("<%=demo1.ClientID %>").focus();
return false;
}
if (document.getElementById("<%=txtFileUpload.ClientID %>").value == "")
{
alert("(*) Upload Field should not be blank");
document.getElementById("<%=txtFileUpload.ClientID %>").focus();
return false;
}
return true;
}
Behind Code
you should call this event inside of pageload.
cmdAdd.Attributes.Add("OnClick", "return validate(event)");
cmdAdd is the id of button. validate is function name which is used in javascript