Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the code of my master page, and here i placed a logout button click event that do the stuff. i applied this master page on different .aspx pages. My problem is that when ever i press enter button on that every aspx page, it logges me out from my website. did i made any mistake? Help me soon...

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class UserMasterPage : System.Web.UI.MasterPage
{
    SqlConnection con = new SqlConnection("Data Source=.\\sql2008;initial catalog=ProductivePlusDB;user id=sa;password=123456");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["emailid"] == null || Session["emailid"].ToString() == "")
        {
            Response.Redirect("Default.aspx");
        }
        string qry = "select *from ShopOwnMast where EmailId='" + Session["emailid"] + "'";
        con.Open();
        SqlDataAdapter adp = new SqlDataAdapter(qry, con);
        DataSet ds = new DataSet();
        adp.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
            if (!IsPostBack == true)
            {
                lbluname.Text = ds.Tables[0].Rows[0][1].ToString();
            }

        }

        
    }
    protected void btnLogOut_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("Default.aspx");
    }
}


This is the logout button code in that master page:

ASP.NET
<div class="top-menu">
               <ul class="nav pull-right top-menu">
                    <li><asp:Button Class="btn btn-theme04" ID="btnLogOut" runat="server"
                           Text="Log Out"
                           style="color:White; margin-top: 15px; margin-left:10px "
                            onclick="btnLogOut_Click" TabIndex="10"></asp:Button></li>
               </ul>
           </div>


What I have tried:

I placed TabIndex ="10" for the solution but it didnt works

i thing this button is selected as default.
i don't have any idea how to fix it.
Posted
Updated 14-Apr-16 1:05am
v2
Comments
Member 12003400 14-Apr-16 3:43am    
because it is setting tab index on that button and not moving further. Are you setting tab index in master page? If not required, remove it from master page and place in content page.
jaket-cp 14-Apr-16 4:18am    
have a read of this:
http://stackoverflow.com/questions/4209903/asp-net-page-enter-key-causing-post-back
it should give you a few options to do what you want.

http://lmgtfy.com/?q=asp.net+form+disable+enter+submit

This is happening because everything on your page is in a single form so when you press enter it triggers the first button, which is your logout button. You have to put the form elements in your content page inside an asp:Panel and set the DefaultButton to be the button you want clicked when you press [enter]

asp.net - how to set a default &#39;enter&#39; on a certain button - Stack Overflow[^]

That way when you press enter in a textbox in your content page it will trigger the button you have specified instead.
 
Share this answer
 
Comments
jaket-cp 14-Apr-16 4:46am    
nice
ASP.NET
<div class="top-menu">
            	<ul class="nav pull-right top-menu">
                     <li><asp:button class="btn btn-theme04" id="btnLogOut" runat="server" xmlns:asp="#unknown">
                            Text="Log Out" 
                            style="color:White; margin-top: 15px; margin-left:10px " 
                             onclick="btnLogOut_Click"  UseSubmitBehavior="False"></asp:button></li>
                </ul>
            </div>


USeSubmitBehaviour="False" Solved my problem
Thnks to all :) 
 
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