Solved

does not exist in the current context

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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