Results 1 to 4 of 4

Thread: calling objects in asp.net [beginner's question]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    425

    calling objects in asp.net [beginner's question]

    Hi All, I have coded a class with the namespace quiz, it contains some methods like adding questions into database and validations.

    Now i want to use it with asp.net, what do i need do in order to be able to call the class in code behind or in the asp.net page itself.

    Another question is how do i pass an object (maybe a car object with mileage values, model etc) from 1 aspx page to another or keeping it in the session so i can retreive it whenever i need it.

    Sorry, but i have tried to google and search the forum but couldnt get any answers. Maybe my phrasing for the search is bad. Thanks in advance.

    cheers

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: calling objects in asp.net [beginner's question]

    Question 1)
    You should just be able to add a reference to your ASP.Net project and use the object from there.

    Question 2)
    If you want to add objects to your session, I'm going to reffer you to the same question I had awhile back:
    http://www.vbforums.com/showthread.php?t=377286
    The example uses a dataset, but it would be easy to do the same thing with a structure.

    Bah Bah Bah
    ViewState is for current page only. You would have to use session. Ignore that link! I suck...
    Last edited by sevenhalo; Mar 6th, 2006 at 03:32 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    425

    Re: calling objects in asp.net [beginner's question]

    To sevenhalo, Thanks for the prompt reply. It helped.
    You don't suck. We are all learning.

  4. #4
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: calling objects in asp.net [beginner's question]

    Quote Originally Posted by hyper88
    Now i want to use it with asp.net, what do i need do in order to be able to call the class in code behind or in the asp.net page itself.
    You have to instantiate it:
    VB Code:
    1. Dim oQuiz as new Quiz

    And then you use the newly created oQuiz object to access methods and properties.

    EDIT: If that class is a stand alone DLL library, you have to reference it to the proyect, and THEN instantiate it.

    Quote Originally Posted by hyper88
    Another question is how do i pass an object (maybe a car object with mileage values, model etc) from 1 aspx page to another or keeping it in the session so i can retreive it whenever i need it.
    If it's a complex object, like a array of strings, just use sessions.

    You can do:
    VB Code:
    1. Dim myObject(5) as String
    2. Session("myObject") = myObject

    And to read it from anywhere:
    VB Code:
    1. Dim myObject() as string = Session("myObject")

    To check if the Session("myObject") actually has a value, you can do this:
    VB Code:
    1. If Session("myObject") Is Nothing = False Then
    2.    'do something
    3. End If

    HTH
    HoraShadow
    Last edited by HoraShadow; Mar 6th, 2006 at 06:35 PM.
    I do like the reward system. If you find that my post was useful, rate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width