Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2009, 11:56 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context

Hi,

I have migrated a web application in VS .NET 1.1 to .NET 3.5 and everything went well.

I then added two protected variables to the .cs file and assigned values to them.

No, when I try to access those varibles in the ASPX page like this:



<spanstyle="margin-left: 5px;">
<%=partOneStep %>
<%=partTwoStep %>

</span>




I get the following error:

The name "partOneStep" does not exist in the current context.
The name "partTwoStep" does not exist in the current context.

I would appreciate if someone could shed some light. What is going on here? It is a simple server write in the ASPX page. I have tried public instead of protected but it did not work as well.

Cheers

C

publicclass_default: ChoicesNetBase{
protectedstring partOneStep;
protectedstring partTwoStep;


private
void Page_Load(object sender, System.EventArgs e)
{
AppConfig cfg = newAppConfig();
partOneStep = cfg.GetValue("DefaultStepPartOne");
partTwoStep = cfg.GetValue("DefaultStepPartTwo");
}


}

In the ASPX file

<spanstyle="margin-left: 5px;">
<%=partOneStep %>
<imgsrc="../browser/images/icon_plus.gif"/><imgsrc="../browser/images/Category.gif"/>
<%=partTwoStep %>
</span>
 
Old February 27th, 2009, 05:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

How does the rest of your page look? Is this a Web Site Project or a Web Application Project? It works fine for me, so something else must be going on.

BTW, the preferred way to do this is to use a Literal control:
Code:
<span style="margin-left: 5px;">
<asp:Literal runat="server" id="partOneStep" />
and then in code behind:
Code:
partOneStep.Text = cfg.GetValue("DefaultStepPartOne");
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 28th, 2009, 08:32 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context

Hi Imar,

Thanks for your reply.

Could you please clarify your question below? :

"Is this a Web Site Project or a Web Application Project?"

What is the difference between a Web Site Project and a Web Application Project?

I also think that the code is fine. I was wondering if there is any configuration I have to set in the web config file so that I can use this code.

I have removed the page from the solution and then added a new one with the same name and copied the code back to it and it seem to be working now.

But it will be a nightmare to have to delete all pages of the site and add them back again.

Any ideas?

Cheers
 
Old March 1st, 2009, 05:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For the difference between the two, take a look here:

http://www.compiledthoughts.com/2008...n-project.html

Do your files have an additional *Designer.cs code behind file? If not, try right-clicking a page (or the the whole site) and click Convert to Web Application". This will regenerate the code behind file.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 1st, 2009, 02:20 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context

Hi Imar,

My files do not include the Designer.cs code hehind files. It only contains the .cs and aspx files. I had already noticed it.

When I tried to right click both the page and the whole site I did not get the "Convert to Web Application" context menu entry.

Do you think I am stuck with it and will have to remove all the pages and add them again?

Cheers
 
Old March 1st, 2009, 04:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't know as you didn't answer the question about the project type. Is this a Web Site Project or a Web Application Project? WAPs need designer files, WSP don't....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 2nd, 2009, 08:58 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context Reply to Thread

Hi Imar,

In one of my previous postss I asked if you could explain to me the difference between a Web Site Project and a Web Application Project.

But since you did not anwers that I was not able to give you that information.

Could you please explain to me how to find out if it is a WAP or WSP?

Cheers
 
Old March 2nd, 2009, 10:39 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context

Imar,

I am not sure if this helps but I am using IIS 5.1 and have folder set up under Web Sites in IIS.

cheers
 
Old March 2nd, 2009, 11:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

And as a reply I posted this link:

http://www.compiledthoughts.com/2008...n-project.html

You create a Web Site Project through File | New Web Site
You create a Web Application Project through File | New Project | ASP.NET Web Application

The details of the two are in the above link.

How you run the site (e.g. IIS) doesn't matter. IIS can run both project types.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 3rd, 2009, 12:41 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default The name 'partOneStep' does not exist in the current context

Hi Imar,

Thanks for you reply and URL.

I assume this application is a Web application Project since I have a proj file in the folder.

NETQuestQR_3_5.csproj

Is there anything I can do to get the variable to work in the ASPX page?

Cheers

P





Similar Threads
Thread Thread Starter Forum Replies Last Post
The name 'txtOperande1' does not exist in the current context stevemcd999 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 3 February 25th, 2009 11:58 PM
Unable to set context in web.xml or context.xml. dchicks Apache Tomcat 1 March 7th, 2008 07:59 AM
Position of a node outside current context QuickSilver002 XSLT 2 April 19th, 2007 02:07 PM
Force current rec on screen if errors exist wscheiman Access VBA 4 November 4th, 2003 02:39 PM
context help smukher Visual C++ 0 June 19th, 2003 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.