Currently, I am working on creating a login page using asp.net and jQuery Mobile.
After the user clicks on the login button, I perform some processing in C# before calling the JavaScript function.
The issue I am facing is that when the login button is pressed, the page reloads before executing the JavaScript, which is not the desired behavior.
Below is a snippet of my code:
<asp:Button name="login" ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
C#:
protected void btnLogin_Click(object sender, EventArgs e)
{
if (String.Format("{0}", Request.Form["username"]) != "" && String.Format("{0}", Request.Form["password"]) != "")
{
ClientScript.RegisterStartupScript(GetType(), "key", "login();", true);
}
else
{
//todo
}
}
JS/jQuery:
<script type="text/javascript>
function login() {
jQuery(function () {
jQuery.ajax({
beforeSend: function () {
$.mobile.loading('show', {
text: 'Processing...',
textVisible: true,
theme: 'a'
});
},
type: "GET",
url: "Handler.ashx",
data: "method=validate",
success: function (data) {
$.mobile.loading('hide');
//$.mobile.changePage("HomePage.aspx", { transition: "fade" });
}
});
});
};
</script>
Do you have any thoughts or suggestions on this matter?
Thank you!
EDIT: I still require the server-side code for handling password encryption in C#