Harish M

Harish M

  • NA
  • 6
  • 10k

Prevent Parent page from reloading when submit button click

Sep 19 2014 5:46 AM
Hi,
 
         In master page i have Login Anchor tag. When i click this anchor  tag, Login form will popup on same page where they click. 
         There is no problem, If credentials are valid. But in submit button if username or password are invalid, the parent page reloads and the popup screen is disabled. Again i have to click on Login anchor tag to login.
 
aspx code
 
Login Anchor Tag
 
<div class="btn-sign">
            <a href="#login-box" class="login-window" id="login_pop" runat="server" >Login In</a>
</div> 
 
Popup Form
<div id="login-box" class="login-popup">
         <a href="#" class="close">
                  <img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" />
         </a>
        <form class="signin" action="#" method="post">
               <div style="margin-bottom: 17px; padding-bottom: 11px; border-bottom: 1px solid #E6E6E6;float: left; width: 100%;">
                           <div style="float: left; margin-left: 30%;">
                                    <img src="images/popup_logo.png" alt="LOGO" />
                          </div>
                          <div style="text-align: center; margin: 8px 0px 3px 48px; float: left; width: 74%;color: #1B4C7B;font-                             family:Verdana; font-size:14px; font-weight: bold;">
                                       Welcome To Silicon Home
                           </div>
             </div>
 

   <div class="popup-form">
            <fieldset class="textbox">
               <label class="username">
                        <asp:TextBox ID="user_name" runat="server" placeholder="Username or Email"></asp:TextBox>
              </label>
     
               <label class="password">
                     <asp:TextBox ID="user_password" runat="server" placeholder="Password" TextMode="Password"></asp:TextBox>
               </label>
  
               <asp:Button ID="login_btn" runat="server" Text="Sign in" OnClick="login_btn_Click" />

               <div style="float: left; width: 100%; margin-bottom: -4px;">
                             <p style="margin-top: 15px; margin-bottom: 5px; float: left; width: 45%;">
                                          <a class="forgot" href="#">Not yet Registered?</a>
                             </p>
                              <p style="margin-top: 10px; margin-bottom: 5px; float: left; width: 38%; margin-left: 57px;">
                                             <asp:Label ID="Login_Status" runat="server" Text="" ForeColor="Red"></asp:Label>
                              </p>
               </div>
       </fieldset>
</div>
</form>
</div> 

Java script
<script type="text/javascript">
$(document).ready(function () {
$('a.login-window').click(function () {

// Getting the variable's value from a link
var loginBox = $(this).attr('href');

//Fade in the Popup and add close button
$(loginBox).fadeIn(300);

//Set the center alignment padding + border
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;

$(loginBox).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});

// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);

return false;
});

// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function () {
$('#mask , .login-popup').fadeOut(300, function () {
$('#mask').remove();
});
return false;
});
});
</script> 

.cs code
 
protected void login_btn_Click(object sender, EventArgs e)
{
            using (SqlCommand cmd = new SqlCommand("UserLogin"))
            {
                     using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                           con.Open();

                           cmd.CommandType = CommandType.StoredProcedure;
                           cmd.Parameters.AddWithValue("@uname", user_name.Text.Trim());
                           cmd.Parameters.AddWithValue("@password", user_password.Text.Trim());

                             SqlParameter emp_status = cmd.Parameters.Add("@retvalue", SqlDbType.Int);
                             emp_status.Direction = ParameterDirection.Output;

                              SqlParameter login_username = cmd.Parameters.Add("@name", SqlDbType.VarChar, 100);
                              login_username.Direction = ParameterDirection.Output;

                              cmd.Connection = con;

                              cmd.ExecuteNonQuery();

                              string temp = login_username.Value.ToString();
                              int s = Convert.ToInt32(emp_status.Value);
                              if (s == 0)
                              {
                                    Login_Status.Text = "Invalid login or password";
                                    return;
                              }
                             else if (s == 1)
                            {
Session["User_Name"] = user_name.Text;
Response.Redirect("~/product.aspx");
                           }
                  }
         }
 
Please help me, to solve this problem