Reputation: 9074
I am new with javascript.
I wanted to navigate the page on sucessfull, enterance of loginID and password.
(for the time being, i have programmed for any login id and password, validation kind of work).
For that i have used location.replace("Registration.aspx");
My code is following:
<script type="text/javascript">
var flag = 0;
function Validate() {
if (document.getElementById('txtLoginId').value == "") {
flag = 1;
document.getElementById('lblLoginID').innerHTML = "Enter LoginID";
}
else {
document.getElementById('lblLoginID').innerHTML = " ";
}
if (document.getElementById('txtPassWord').value == "") {
flag = 1;
alert("dddddd"+flag);
document.getElementById('lblPassword').innerHTML = "Enter Password";
}
else {
document.getElementById('lblPassword').innerHTML = "";
}
if (flag == 1) {
return false;
}
else {
// Response.Redirect("Registration.aspx");
location.replace("Registration.aspx");
return true;
}
}
</script>
Button Code:
<asp:Button ID="btnLogin" runat="server" Text="LogIn"
onclick="btnLogin_Click" OnClientClick="return Validate();" />
What can be mistake in it?
Please help me.
Upvotes: 0
Views: 515
Reputation: 2149
Assuming you have to process the input from user in code behind:
Client script validation function should be like this:
function Validate() {
var flag = 0;
if (document.getElementById('txtLoginId').value == "") {
flag = 1;
document.getElementById('lblLoginID').innerHTML = "Enter LoginID";
}
else
document.getElementById('lblLoginID').innerHTML = " ";
if (document.getElementById('txtPassWord').value == "") {
flag = 1;
document.getElementById('lblPassword').innerHTML = "Enter Password";
}
else
document.getElementById('lblPassword').innerHTML = "";
return (flag != 1);
}
In code behind:
public void btnLogin_Click(object sender, EventArgs e)
{
/* username and password processing code
....
*/
Response.Redirect("Registration.aspx");
}
Upvotes: 1
Reputation: 2707
location.replace("Registration.aspx");
return false;
return false
instead of return true
.It will work.
Upvotes: 1
Reputation: 276303
You are using a serverside function
Response.Redirect
on client side code. Use
window.location
on client.
Upvotes: 1