I'm making a simple web page in visual studio 2008 and I need it to authenticate the data clientside before it is sent to the server for further authentication. I have the serverside part working but I can't for the life of me get it to run the javascript. Is there a simple way to do this?
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
String accountName = "Jon";
String accountPassword = "school";
if ((TextBox1.Text == accountName) && (TextBox2.Text == accountPassword)) Label3.Text = "Hello " + TextBox1.Text;
else Label3.Text = "Login error";
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function validatePassword()
{
document.write("<h1>THE JAVASCRIPT RAN!!</h1>");
if (TextBox2.value.length < 8)
{
alert("password must be at least 8 characters");
return false;
}
else return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Login Please<br />
<br />
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="username"></asp:Label>
<p>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="password"></asp:Label>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Login"
onclientclick="return validatePassword" onclick="Button1_Click"/>
</p>
<p>
<asp:Label ID="Label3" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
This couch is the comfiest!
Street Fighter 4 (pc): sdurien
Steam: Jon
http://steamcommunity.com//profiles/76561197970923897/home
Posts
EnableClientScript="True"
which will basically transform the validation from server side to auto-generated javascript... that should do quite a bit for you.
If not, then you have to intercept the click event on the form button and run a big validation function and return it false if anything doesn't pass.
we also talk about other random shit and clown upon each other
Street Fighter 4 (pc): sdurien
Steam: Jon http://steamcommunity.com//profiles/76561197970923897/home