.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

'Session' does not exist in the current context

Posted By:      Posted Date: October 06, 2010    Points: 0   Category :ASP.Net

In my application I am trying to read and write session variables in a class file using C#.  What do I need to use to access the Session variables?

View Complete Post

More Related Resource Links

CS0103: The name 'Helper' does not exist in the current context


Hey i have a Class named Helper.cs inside my App_Code folder.

And i get this error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'Helper' does not exist in the current context

Source Error:

Line 26:         {
Line 27:             SqlConnection con = new SqlConnection(Helper.ConnectionString());

The name 'User' does not exist in the current context.


Hey guys,

I've got a literal control to display the username of the user logged into our companies intranet system, originally I had a LoginName control but couldn't get strip to remove the domain from the username (as the format is domainname\username) so I'm trying it this way.

    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");

        if (Parts.Length == 2)
            loginName.Text = Parts[1];
            loginName.Text = User.Identity.Name;


    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");

Login control - Controls do not exist in current context

Hi all,Trying to set up the Login control as a User control, but none of the controls exist in the current context?None of my code below is recognised? What's going on here please? I've rebuilt the solution many times.if (Membership.ValidateUser(this.UserName.Text, this.Password.Text))        {            FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);        }        else        {             Msg.Text = "Login failed. Please check your user name and password and try again.";        }

The name 'InitializeComponent' does not exist in the current context

Hello!I'm creating  a control library and consequently a class.Visual studio compiler is giving my followed error, when I wrote InitializeComponent();The name 'InitializeComponent' does not exist in the current contextCan anybody help me please?

Compiler Error Message: CS0103: The name 'lblRegion' does not exist in the current context

i am gettign this error Compiler Error Message: CS0103: The name 'lblRegion' does not exist in the current context Source Error: Line 31: {Line 32: Line 33: lblRegion.Text = dt.Rows[0]["RegionName"].ToString();Line 34: lblCountry.Text = dt.Rows[0]["CountryName"].ToString();Line 35: lblCountryCode.Text = dt.Rows[0]["CountryCode"].ToString(); this is source code:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net;using System.Xml;public partial class CSharp : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        //Get IP Address        string ipaddress;        ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];        if (ipaddress == "" || ipaddress == null)            ipaddress = Request.ServerV

The name 'id' does not exist in the current context


        int Id = Convert.ToInt32(ddlCardDetails.SelectedValue.Split('|')[0]);
        tbl_Payment democustomer = ctx.tbl_Payments.SingleOrDefault(c => c.ID == id);


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'id' does not exist in the current context

Source Error:

Line 523:
Line 524:        int Id = Convert.ToInt32(ddlCardDetails.SelectedValue.Split('|')[0]);
Line 525:        tbl_Payment democustomer = ctx.tbl_Payments.SingleOrDefault(c => c.ID == id);
Line 526:
Line 527:

The name 'Profile' does not exist in the current context


So, I'm using the .NET 2.0 Profile object to manage custom user data on an internal site for my company. Everything seems to be working flawlessly until I realized I was going to have to add a redundant block of code to every aspx page in order to take advantage of the Profile.

At this point I decided to create a custom base page that could be inherited by all of my aspx pages. Seemed like the right idea, until I got the above error:


The name 'Profile' does not exist in the current context


I might be missing out on how/when the Profile object is getting built but I was wondering if anyone had any suggestions on how to access the Profile object from a base page/class.

Repeater Control Does not exist in current context, but other controls do


I have an aspx page containing a number of asp:Repeater Controls.

Im not using the default code-behind file that is generated, ive changed this to file in a different folder.

In the code-behind, i populate the repeater controls, all was workign fine until i added another repeater control to the aspx page.
In the code-behind, the intellisense picks up this control and i can access its methods and properties to set the datasource and bind the data. However, when i go to build the project, i get an error "The name Repeater1 does not exist in the current context"

Firstly, all the other repeater controls, declared in exactly the same way, do not throw throw this error.
Secondly, yes the repeater does have a runat="server" tag.
Thirdly, It is not inside any other controls.

I have tried various different methods of accessing this repater instead of just "Repeater1." but each returns null:

Repeater r1 = (Repeater)Page.FindControl("Repeater1") ;
Repeater r1 = (Repeater)Page.Master.FindControl("Repeater1"); 
Repeater r1 = (Repeater)Master.FindControl("Repeater1") ;

Ive no idea why this "doesnt exist in the current context" as all the other controls on this page do, even if i create a literal i get the same problem

The name 'PopularApplicationSkins' does not exist in the current context for Ribbon.


Hi, when i want to set Office2007 style to my Ribbon, throw an exception and say:

The name 'PopularApplicationSkins' does not exist in the current context !

what should i do?


Amin Mashayekhi

Label does not exist in the current context error


Hello All,

I am facing a weird issue.I have a label on the front end but when I try to use it on the code-behind and run my code I obtain an error: Label does not exist in the current context! The label is shown in intellisense and was working earlier.My team mate had created a back up of the file and it stopped working after that.I deleted the back up files and tried but it doesn't seem to work.Any suggestions will be greatly appreciated.

The following is the code snippet of the front end as well as the code behind:

 <div id="weather">
     <img src="sunny.jpg" alt="sunny" height="40px" width="40px"/>
     <p><i>(5 minute Averages)</i></p>
            <td><b><font size="2px">Current Time</font></b></td>
            <td><asp:Label runat="server" ID="Label_Time"></asp:Label></td>
       <tr><td><b><font size="2px">Temperature</font></b></td><td><asp:Label runat="server" ID="Label_Temperature"></asp:Label></td>

The name xxx Does Not Exist in the Current Context


I add a label to a page and set its ID to LabelEditMessage and debug, and there it is.  Then in the code behind page (C#) I add a line of code LabelEditMessage.Text="test";  If I build, the build succeeds, but if I press the debug button it does another build that fails and tells me that LabelEditMessage Does Not Exist in the Current Context.  Intellisense knows about it, and I use that to enter the reference to be sure I am not mispelling. 

So I tried using FindControl, and that fails with a null reference.  It is there, I can see it, but Visual Web Developer refuses to acknowledge it's existence in the code behind file.  If I remove the code reference it builds fine and I can see the label with its default value when i debug, but I cannot reference the label in code.

I'm stumped.  It's such a simple thing that I have done many times before.  I just don't know what else to try.

I had an almost identical problem once before in the page load event trying to set the ConnectionString property of an SqlDataSource.  I tried everything I could think of for days.  Then one day I deleted a validator element and it suddenly started working, and I replaced the validator and it kept on working, so I dismissed it as a fluke.  But now it is back, only this time with a label rather than an SqlDataSource. 

cmd does not exist in current context


Ok Guys and Gals

I am having a problem and yes I don't know what I am doing :)

I need to have a calendar control or really any control i use set a parm to the selected or entered value. I have done some reading and I thought I found the answer but I am getting cmd does not exist in current context asp.net

page load 

            string RequestDate = "Blah"; 

      protected void CalendarRequestDate_SelectionChanged(object sender, EventArgs e)

            cmd.Parameters.AddWithValue("@RequestDate", CalendarRequestDate.SelectedDate.ToShortDateString());
            LabelRequestDate.Text = @RequestDate;


CS0103 The Name 'Layout' does not exist in the current context



I am working on WebMatrix Samples on using Layout and Razor Syntaxe. Unfortunatly I have an CS0103 Server error when a run the site that says that "The name 'Layout' does not exist inthe current context.

The sample is very easy. Two files, Index.cshtml and _Layout.cshtml in the same directory.

The "_Layout.cshtml" content is:
<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8" />
        <title>My WebSite</title>

And the "index.cshtml" centent is:
    Layout = "~/_Layout.cshtml";

<h1>Hello World!</h1>
<h2>Hello World!</h2>
<h3>Hello World!</h3>

 The error occurse on the line 2 of the index.cshtml file.

I tred to use Layout = "_Layout.cshtml" but without success. So can you please help me with this issue.

For information :

The name 'intPageID' does not exist in the current context


Hi all,

In my web app i call C# function inside javascript

function DeletePage(intPageID) {
            document.getElementById("ctl00_ContentPlaceHolder1_hdnPageID").value = intPageID;
            if (confirm("Are you sure you want to delete selected file?")) {
               <% DeleteData(intPageID); %>
                window.location.href = "MiniSite_Pages.aspx";

in code behind

 public void DeleteData(int intPageID)
        MiniSitePagesService objMiniSitePagesService = new MiniSitePagesService();

but i have error 'The name 'intPageID' does not exist in the current context'

can anyone help me please?

Thanks in advance.

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Context.Session always is Nothing

Hi!In order to add logging of user's activities across all application' pages, I've added this HttpModule to handle Session_Start & Session_end instead of Global.asax, because If I try to use Global.asax I see no event firing, even on BeginRequest Now I can see that Session_start & BeginRequest fire properly, but on every event I got nothing as Context.Session. I see this property is readonly, so I must be missing some step to initialize it. Thanks in advanceMarco-----------module begins ---------------Imports SystemImports System.WebImports System.CollectionsNamespace gdc    Public Class MyHTTPHandler        Implements IHttpModule        Implements IRequiresSessionState        Public ReadOnly Property ModuleName() As [String]            Get                Return "MyHTTPHandler"            End Get        End Property        Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init            AddHandler

HTTPContext.Current.Session losing the variable sporatically

I have noticed a strange behaviour in my ASP.net 2.0 application. I have some logic in my aspx page that accesses some Session variables fine, then accesses some app_code and most of the time the HTTPContext.Current.Session returns the variable back fine.  However, I have noticed that sometimes this Session returns null, like it has lost it's "pointer" to the current HTTPContext. Is this a known bug, has anyone seen something like this before?   Any help would be appreciated, thanks, Mark. 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend