Usercontrol and Variables

Im really new to ASP.NET and have a background in ASP VB coding.
I have been reporgramming a webpage from ASP to the last week and basically rewritten most of it.
Forms and formchecks work great but the rest of ASP.NET is kinda abacadabra for me.

I have some website data stored in an Access database (general info about the site, keywords, title etc) i use this info from a table cuz I want to make the site multilingual.
Im trying to write this data to variables in my site which I can use in all scripts on the site.
So I include this ascx file and in this file I try this:

Sub PageLoad(ByVal sender As System.Object, ByVal e As System.EventArgs)
                ........................ 'not important code for this question
      While DBReader.Read()
            Dim strSiteInfoKeywords As String = DBReader("site_info_keywords")
            Dim strSiteInfoKeywordslong As String = DBReader("site_info_keywordslong")
            Dim strSiteInfoHome As String = DBReader("site_info_home")  
      End While
End Sub

So I thought I could use these values in the rest of my site, since this ascx usercontrol is used on each page.
But somehow the variables declared in here cant be used in the ASPX files.

Why is this and how can I fix this????

Variables from includes files in good old ASP could be used vice versa (base file to include, include file to base) without any hassle....
I need this project fixed this comming weeks, this crap gives me some serious headaches :)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

As long as this data is general for the application you can use the application object to store this data and to retreive it each time a new page is loaded. In order to do this you need to handle the Application_Init event that occurs when the application is initiated. You retreive the data from you Access database and you can store a DataSet or DataTable with the fetched data in your Application object.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fryslanAuthor Commented:

Thanx alot for that, I thought I could only define those Application objects in the Global.asax, but it works for the rest too. But what about another thing. I define a value Dim intId in the Ascx file, and I wanna use it in the Aspx file that uses that Ascx file? Is there a way to do that, these variables change depending on a Querystring in the URL, so its not smart to use Application object, right??
You can use the Session object for variables that change for each user across the pages and the Application object for those variables that are not changing.

fryslanAuthor Commented:
OK, session variables it is :)
Do I need to close these session variables on every page then too?
And why cant I declare the var intId like global, so I can use it in all files which are used in that page, just like in good ol ASP.
Session variables will be available through the user's session. The session will end when the user logs out or when he closes the browser.
You can use cookie variables if you like to...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.