Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am doing a login page validation which requires validation and after that authentication on submit button click. But I am getting validation which I have in my js file but not getting call to the authentication function which is present in the button click of code behind. When I call btn_Click function on button's onserverclick it is not working.

suggest me something How can I resolve this problem.
Posted

Ideally your button should look like below...
ASP.NET
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return ValidateForm()" OnClick="btnSubmit_Click"></asp:Button>

Here ValidateForm() is a JavaScript function which should validate all your required fields and return true if validated, else false.
JavaScript
function ValidateForm()
{
    if(allFieldsValidated)
    {
        return true;
    }
    else
    {
        return false;
    }
}

If it returns true, then button click server event btnSubmit_Click is fired. Else it is not fired.
 
Share this answer
 
Comments
Member 10324774 15-Mar-14 8:37am    
Already I am doing like that only but validation is working but it is not calling the btnsubmit function.
It should work. You have done some other mistakes then.
Member 10324774 16-Mar-14 2:50am    
this is my code snippet...
<form id="Form1" class="login-form" method="post" runat="server">

Login to your account


<div class="alert alert-danger display-hide">
<button id="Button1" class="close" data-close="alert" runat="server"></button>
<span>Enter any username and password.</span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9" id="lblname" runat="server">Username</label>
<div class="input-icon">

<input id="username" runat="server" class="form-control placeholder-no-fix" type="text" maxlength="15" autocomplete="off" placeholder="Username" name="username"/>
</div>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9" id="lblpwd" runat="server">Password</label>
<div class="input-icon">

<input id="password" runat="server" class="form-control placeholder-no-fix" minlength="6" type="password" autocomplete="off" placeholder="Password" name="password"/>
</div>
</div>
<div class="form-actions">
<label class="checkbox">
<input type="checkbox" name="remember" value="1" id="chkbx" runat="server"/> Remember me
</label>
<button type="submit" class="btn green pull-right" id="btnsubmit" onclientclick="return handlelogin()" runat="server" önserverclick="btnsubmit_Click" >
Login
</button>
</div>
<div class="forget-password">

Forgot your password ?


<p>
no worries, click here
to reset your password.
</p>
</div>

</form>

and btnsubmitclick:
protected void btnsubmit_Click(object sender, EventArgs e)
{

using (var client = new HttpClient())
{
try
{
loggger.Debug("User authentication begin: ");
AuthUser authUser = new AuthUser();
authUser.UserName = username.ToString();
authUser.Password = password.ToString();
authUser.AuthType = int.Parse(ConfigurationSettings.AppSettings["AuthType"].ToString());
client.BaseAddress = new Uri(ConfigurationSettings.AppSettings["APIServiceUrl"].ToString());
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(authUser);
loggger.Debug("User authentication request: " + json);
var response = client.PostAsJsonAsync<authuser>("api/authentication/Authenticate", authUser).Result;
loggger.Debug("User authentication response: " + response.IsSuccessStatusCode);
if (response.IsSuccessStatusCode)
{
var data = response.Content.ReadAsStringAsync().Result;
if (data != "null" && data.Length > 0)
{
User user = (User)js.Deserialize(data, typeof(User));
loggger.Debug("Authenticated user : " + user.UserName + " RoleID: " + user.RoleID.ToString());
if (user != null)
{
switch (user.RoleID)
{
case 3:
Response.Redirect(ConfigurationSettings.AppSettings["ManagementWebUrl"].ToString(), true);
break;
default:
Response.Redirect(ConfigurationSettings.Ap
I cannot check all these code. But as I suggested you, please check the Button code. It is different than yours. Can you implement as I suggested you?
Member 10324774 16-Mar-14 9:16am    
sorry I am using html button with id and runat="server" attribute. May be for that reason it is not working I think.
Suggest me something if that is html bitton how can I do?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900