Solved

does not exist in the current context

Posted on 2014-01-22
5
640 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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