473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Access to variables in an asp.net user control vs an include file

20
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

Expand|Select|Wrap|Line Numbers
  1. <% myVar = "something" %>
I could assign many variables here and then use an include

Expand|Select|Wrap|Line Numbers
  1. <!--#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

Expand|Select|Wrap|Line Numbers
  1. <% 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?
Dec 19 '09 #1

✓ answered by Frinavale

User Controls aren't really what you're looking for but they are similar to what you want: they are "semi-pages" included into other pages...so they could probably do what you want them to do except that their main purpose isn't really to do this.

I'm only just starting to get used to the style that you're so comfortable with because I'm starting to do a little more PhP programming. PhP does the same thing: uses includes to "import" variables between pages. It's weird for me to work this way and I get annoyed when I try to figure out where these variables are coming from when pages include several different imports...

I can see how ASP.NET would be strange for you because your programming style is very different from the programing style that ASP.NET uses.

I think if I were in your place I'd probably make a Class that stores these variables for you in one place. I typically use a class ("Utils") that contains "Lists" and other variables (along with methods) that are shared amongst several pages.

Have you considered using a Static/Shared Class like my Utils class?

Have you considered using the web.config file to store the variables that are shared amongst several pages?

Creating a base class for your pages sounds like it will also work but I usually think it's overkill. I've seen other posts where people are asking how to use inheritance and base classes for their pages...I never could figure out why they were doing this. Thanks for opening my eyes to their way of thinking.

-Frinny

7 1985
Frinavale
9,735 Expert Mod 8TB
I know it's hard moving from one environment to another but when you do you have to keep in mind that each environment has its own way of doing things.

It sounds like someone has already told you what I was going to suggest: to use a User Control.

There are other ways to do this but before I suggest any of them I need to know a little more about these variables.

Are they global variables that are accessible on many of your pages (shared amongst them)?

How are you using these variables?
What are they for?

-Frinny
Dec 21 '09 #2
jumbojs
20
Well, in the original program it was an import process that had a web interface. The variables were "global" but they weren't really defined as global but the scope was global only because that when you use server side includes the file that is injected into the page has access to all the variables from the parent page. I did find something on Page Inheritence and it sounded like it used to work on ASP.NET 1.1 where if you had a control on the parent page you could access the parent control variables but now in 2.0 it sounds like you have to do a bunch of stuff that makes this almost silly. Like create a base class and put it in APP_CODE and then inherit from that class and then your control can have access to the parent control variables... all of which is much more difficult then what I used to do with includes. I'm not really seeing the advantage of using user controls here.
Dec 21 '09 #3
Frinavale
9,735 Expert Mod 8TB
User Controls aren't really what you're looking for but they are similar to what you want: they are "semi-pages" included into other pages...so they could probably do what you want them to do except that their main purpose isn't really to do this.

I'm only just starting to get used to the style that you're so comfortable with because I'm starting to do a little more PhP programming. PhP does the same thing: uses includes to "import" variables between pages. It's weird for me to work this way and I get annoyed when I try to figure out where these variables are coming from when pages include several different imports...

I can see how ASP.NET would be strange for you because your programming style is very different from the programing style that ASP.NET uses.

I think if I were in your place I'd probably make a Class that stores these variables for you in one place. I typically use a class ("Utils") that contains "Lists" and other variables (along with methods) that are shared amongst several pages.

Have you considered using a Static/Shared Class like my Utils class?

Have you considered using the web.config file to store the variables that are shared amongst several pages?

Creating a base class for your pages sounds like it will also work but I usually think it's overkill. I've seen other posts where people are asking how to use inheritance and base classes for their pages...I never could figure out why they were doing this. Thanks for opening my eyes to their way of thinking.

-Frinny
Dec 21 '09 #4
jumbojs
20
So, it sounds like the static class might work. So you have a bunch of static variables and methods that are shared among all the pages? The only problem is that these classes need to talk back to the aspx page so there can be some user feedback on the progress of the import but I don't seeing that being much of a problem.
Dec 21 '09 #5
Frinavale
9,735 Expert Mod 8TB
I'm not sure what you mean by "provide feedback about the status of the import".
Let me know how the static class works out for you :)

-Frinny
Dec 21 '09 #6
jumbojs
20
Status would mean, as the import process is running, the user would see information on the web page like number of records processed, the time elapsed...etc.

I will let you know about the static variables, thank you.
Dec 21 '09 #7
Frinavale
9,735 Expert Mod 8TB
Oh, I was just helping someone else with this.
You may be interested in this thread:

ASP.NET Progress

-Frinny
Dec 21 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael J. Astrauskas | last post by:
I have a site where a user logs in and a session variable I created is used to keep track of the fact that the user is logged in. This various pages query a MySQL database to get information...
4
by: Ben R. | last post by:
Hello, I've got a text-based .inc file that I'm using for my asp.net site's header. I thought about a user control, but if possible, I'd like to avoid it for simplicity's sake. In the main page,...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
35
by: deko | last post by:
Do I get more scalability if I split my database? The way I calculate things now, I'll be lucky to get 100,000 records in my Access 2003 mdb. Here some math: Max mdb/mde size = 2000 x 1024 =...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
3
by: Hutty | last post by:
I'm trying create a calendar control that updates an access database with events. I have some code I managed to piece together. First error I'm running into is the Mycommand.ExecuteNonQuery(). I...
6
by: cyndithomas via AccessMonster.com | last post by:
I new to Visual Basic and am struck on a issue. Have created a Login in Screen for Remote User to access and input data. Want the Remote to be able to login & access the Input Form, and Manager...
1
by: dixcyn04 | last post by:
Ok, now I've run into another little hiccup in my application. The ability to update records already in existance. What is bugging me about this, is the code I will submit was what I found on forums...
7
by: Fred | last post by:
I have a file (access.php) with the db username and pwd, which I include in every php file that needs db access. I'm not clear on how to set the path. I have an account on a shared *nix server,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.