Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How solve this error (The name 'LinkButton1' and 'lbllogin' does not exist in the current context)in masterpage??


C#
public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login"] != null)
        {

            lbllogin.Text = "Welcome" + Session["login"].ToString();
            lbllogin.Visible = true;
            LinkButton1.Text = "logout";

        }
        else
        {
            lbllogin.Visible = false;
            LinkButton1.Text = "login";
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (LinkButton1.Text == "login")
        {
            Response.Redirect("~/login.aspx");
        }
        else
        {
            Session.Clear();
            Response.Redirect("~/home.aspx");
        }
    }
}
Posted
Updated 17-Sep-14 20:07pm
Comments
Kumarbs 18-Sep-14 1:48am    
Can you place your design code? So that it can be easy to provide the solution
Sinisa Hajnal 18-Sep-14 2:09am    
At a guess, you're missing runat="server" in your designer code...but we would have to see your html to know for sure...
mhassan083 18-Sep-14 2:12am    
ok
mhassan083 18-Sep-14 2:12am    
<div id="login" align="right" >
<asp:Label ID="lbllogin" runat="server" ForeColor="white" Text="">
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton
</div>
</div>

1 solution

hi
please add runat="server" tag in your link button .
then use that link button .
By
 
Share this answer
 
Comments
mhassan083 18-Sep-14 2:25am    
already exist sir!
<div id="login" align="right" >
<asp:Label ID="lbllogin" runat="server" ForeColor="white" Text="">
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton
</div>
</div>
mhassan083 18-Sep-14 2:46am    
what is the problem?!

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

  Print Answers RSS


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