Solved

does not exist in the current context

Posted on 2014-01-22
5
615 Views
Last Modified: 2014-02-04
Hi experts

I have declared a Div
 <div id="NEOPlogout" visible="false" runat="server">

on my Site.master page and on Site.master.cs I have a condition to check that if
if (Session["UserName"] == null)
        {
            NEOPlogout.Visible = false;
            menu.Visible = false;

I receive an error when I compile that NEOPlogout
does not exist in the current context
Any suggestion?

THanks
0
Comment
Question by:shpresa
5 Comments
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 166 total points
ID: 39801552
Check the Site.Master.designer.cs file and see if it has a reference to your <div>. It should look like this:

protected global::System.Web.UI.HtmlControls.HtmlGenericControl NEOPlogout;

If it doesn't have that line I would suggest deleting the <div> and re-adding it to see if you can get VS to generate that line.

BTW, I notice in your sample that the <div> doesn't have a closing tag. I'm assuming that's just a omission in your question but you should make sure there is actually a closing tag in the markup.
0
 

Assisted Solution

by:anwarul
anwarul earned 167 total points
ID: 39802248
Check your code behind file name and Inherits property on the @Page directive, make sure they both match.
.cs class name must be places inside HTML markup.

this issue came generally new page created from existing page inherits property was older page.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39802437
Is the DIV declared in the master page itself? What event in the master page are you attempting to access the DIV from?
0
 

Author Comment

by:shpresa
ID: 39804227
Yes div is on my site.master page.

I just created a Div to make it visible or invisible depending on the login credentials. SO on my Site.master.cs I check if they are logged in make the div visible and else invisible.

The div has  a closing tag so no problems on that.

I did copied the div from another page, but it is just a simple div tag.
<div id="NEOPlogout" visible="false" runat="server">
                        <table cellpadding="0" cellspacing="0" id="Extra" align="right" class="PPTHeader">
                        <tr>
                              <td valign="top" align="left" class="PPTHeaderLabel"><b>Welcome</b>&nbsp;&nbsp;<asp:Label ID="txtFirstName" Font-Bold="true" runat="server" CssClass="PPTHeaderLabel" />! </td>&nbsp;&nbsp;
                            
                              <td valign="top" align="right"> <asp:HyperLink ID="HyperLink1" NavigateUrl="~/logout.aspx" Font-Bold="true" ForeColor="Black"  Text="&nbsp;&nbsp;Log Out" CssClass="locator_icon" runat="server">  </asp:HyperLink> </td>
                          </tr>
                        </table>
                        </div>


and on my master.cs page i have

on page load.
        if (Session["UserName"] == null)
        {
            NEOPlogout.Visible = false;
            menu.Visible = false;
        }
        else
        {
          NEOPlogout.Visible = true;
            menu.Visible = true;
           txtFirstName.Text = Session["sFirstName"].ToString();
        }

Error
The name 'NEOPlogout' does not exist in the current context
The name 'txtFirstName' does not exist in the current context      

I did tried talking it out, executing, it gave me no erros, and then I placed again, the error came back.

I do have HTML tag on my site.master page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

and the div is currently insite the Html tag.

Thanks
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 167 total points
ID: 39804461
Well, there is nothing logically wrong with your markup/code, so there must be something else somewhere that is invalidating the page somehow.

Start by commenting out any ContentPlaceHolder elements so that you are just left with the master page code itself, and see if that makes any difference.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now