 |
| 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
|
|
|
|

February 27th, 2009, 11:56 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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;
privatevoid 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>
|
|

February 27th, 2009, 05:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

February 28th, 2009, 08:32 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2009, 05:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

March 1st, 2009, 02:20 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2009, 04:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

March 2nd, 2009, 08:58 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 2nd, 2009, 10:39 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 2nd, 2009, 11:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

March 3rd, 2009, 12:41 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |