Session not available in Visual Studio IDE

A

Axel Dahmen

Hi,

after I've added a property to my web page I can't open it in Visual Studio
Designer anymore. I get the error message "File couldn't be opened in Web
Forms Designer. [...] enablesessionstate page directive required to use
Session object."

I see that Visual Studio Web Forms Designer seems to execute any Property
code when opening the page. But I don't want it to.

How can I check if my page is in design mode so that I can skip any relevant
code during working in Designer?

TIA,
Axel Dahmen
 
G

Guest

Add property? To ASPX page in a code section or in the CodeBehind? I have
added properties in CodeBehind without any problems, but have not tried in
the ASPX itself, so that is the only thing I know of to look at right now. If
you do not get a good direction, post some code so someone can attempt to
repro your steps.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
A

Axel Dahmen

Thanks for trying to help me.

I've created a new Page base class derived from Page, MyPage. Now I'm
deriving all my web pages from MyPage instead of Page. This works very well
so far.

Here's the code I've added to MyPage.cs:

public HostApp CurHostApp

{

get {return (HostApp)Session["HostApp"];}

set {if (value==null || value.Count==0) Session.Remove("HostApp");

else Session["HostApp"]=value;}

}


Due to the Session object referenced in this property, VS Web Form Designer
is not able to show me a design view anymore. So I need to know how to tell
if my code is executed from within VS Designer, so that I can comment out
the code like:

{

get {return VisualStudio.ViewedFromWithinDesigner ? null :
(HostApp)Session["HostApp"];}

}



Axel


---------------------
"Cowboy (Gregory A. Beamer) - MVP" <[email protected]>
schrieb im Newsbeitrag
Add property? To ASPX page in a code section or in the CodeBehind? I have
added properties in CodeBehind without any problems, but have not tried in
the ASPX itself, so that is the only thing I know of to look at right now. If
you do not get a good direction, post some code so someone can attempt to
repro your steps.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


Axel Dahmen said:
Hi,

after I've added a property to my web page I can't open it in Visual Studio
Designer anymore. I get the error message "File couldn't be opened in Web
Forms Designer. [...] enablesessionstate page directive required to use
Session object."

I see that Visual Studio Web Forms Designer seems to execute any Property
code when opening the page. But I don't want it to.

How can I check if my page is in design mode so that I can skip any relevant
code during working in Designer?

TIA,
Axel Dahmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top