views:

226

answers:

2

I've asked this question before but couldn't get the answer I was looking for so I'm going to try it again.

I'm translating pages from old asp to asp.net and I don't want to do this any other way so I really just want to know if this can be done.

In asp, I'd assign a variable on one page

<% myVar = "something" %>

I could assign many variables here and then use an include

<!--#include file="Test2.aspx"-->

then in test2 file, I could access all the variables without having to pass all the variables into the control or declaring them again, like

<% myVar = "something else" %>

I want to do this the dot net way but I have some thirty variables on the page and i don't want to pass a bunch into the user control and I don't want to have to keep declaring the same variables.

All I really want to know is if there is some way to replicate the behavior above in asp.net?

A: 

If by "replicate" you mean "maintain syntax with the same behavior," then no. If you have static variables that you want available throughout your application, or by session, consider initializing them in Global.asax in Application or Session state.

Dave Swersky
+1  A: 

There can be N number of ways to handle this. You can create a master page, declare and assign the variable in master page and use the master page where the variables are required. You can also achieve common look and feel if you are using Master page.

Alternatively you can create a singleton class in which you have defined these variable as set of public properties. You can then use this call in any page you like.

Again there might be other better ways to achieve it.

ARS