Webmatrix, passing variable through pages

Posted on 2011-10-11
Last Modified: 2012-08-13
Hello experts!

I have a table in the database. User cannot change values there, they are kind of hard coded.
I want this table to populate <select> list, I know how to do it on the page where <select> list is placed.

The thing is I would like to populate variable:

var myQuery = db.Query("SELECT * FROM tyoes");

and make this variable visible for many pages to use it to populate many <select> lists on many pages.

How can I do it?

Also: do I have to initialize database on every page I use it?

var db = Database.Open("StarterSite");

Thank you


Question by:panJames
    LVL 32

    Accepted Solution

    you can use session variables to save data that multiple pages will need access to.

    if you a dropdown box thats not going to change throughout the pages, i recommend building it once, and then storing the html for it in a session variable, kind of like this:

    session("dropdownName") = "<select name='dropdown'>" & _
                                                   "     <option value='1'>option 1</option>" & _
                                                   "     <option value='2'>option 3</option>" & _
                                                   "     <option value='3'>option 3</option>" & _

    then you can write out the dropdown on any page by simply doing:


    I would look into session timeouts as well if you take this approach, because if your session expires, you'll lose the data for the dropdown.

    to answer your second question, technically no, you dont need to, you could store the database connection object in a session variable, but this is not common practice as it would waste resources.

    The answer above assumes you're using classic asp
    LVL 32

    Expert Comment

    by:Big Monty
    if you're using .NET, you can use sessions as well:

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now