Solved

does not exist in the current context

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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