Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

does not exist in the current context

Posted on 2014-01-22
5
Medium Priority
?
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 664 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 668 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 668 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 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