Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 12th, 2006, 03:26 PM
Authorized User
 
Join Date: Aug 2006
Location: delhi, delhi, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default Placing Session variable

hi,
I have to use a common function in all the .aspx.vb files containing a function which returns a string of session and application variables. eg

Function ABC() as string
 dim MyString as string
MyString = Mystring & Session("a")
MyString = Mystring & Session("b")
return Mystring
End Function

i want to put this function in a common file from where i would be able to use this function.

Class File is not supporting session and application variables.

Please get me know the answer
Thanks in advance.
Kamal
  #2 (permalink)  
Old September 12th, 2006, 03:35 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Put the function in a class file and pass the session variables in as arguments:

Public Function abc(byVal valueA as string, byVal valueB as string) as string
 Dim myString as string
 mystring += valueA
 mystring += valueB
 return mystring
End Function

"The one language all programmers understand is profanity."
  #3 (permalink)  
Old September 12th, 2006, 03:57 PM
Authorized User
 
Join Date: Aug 2006
Location: delhi, delhi, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default

unfortunatley, your solution doesnt work properly for my problem. actually my problem is as i have to use 7 session variable and 2 application variable in the function ABC. if i will pass each time as 9 parameter then it would be much convenient to put this function in the same .aspx.vb file.

Please give me any other solution if anybody can
  #4 (permalink)  
Old September 13th, 2006, 04:53 AM
Authorized User
 
Join Date: Sep 2006
Location: Bangalore, Karnataka, India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
You can use class files surely to achieve the same. So if you are using vb, you will have a file like class1.vb which will be placed in the app_code folder of the application.

Let me write a code for you to help you clear than giving cryptic codes as answers:)

Three files in the project used below are:
Default.aspx, default.aspx.vb and class1.vb (in app_code folder)

default.aspx - has a button (button1) and a textbox (text1)
default.aspx.vb file will have the following code for page_load and button click

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        HttpContext.Current.Session("session_a") = "Vincent"
        HttpContext.Current.Session("session_b") = "Thomas"
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim seschk As New Class1
        Dim sess_string As String
        sess_string = seschk.abc()
        Text1.Text = sess_string
    End Sub
End Class



While class1.vb, the class file will have the following code.
Imports Microsoft.VisualBasic

Public Class Class1
    Public Function abc() As String
        Dim xStr As String = ""
        xStr = xStr & HttpContext.Current.Session("session_a") & " "
        xStr = xStr & HttpContext.Current.Session("session_b")
        Return xStr
    End Function
End Class


I have set the sesssion variables in the page load of the form itself, however you can set it anywhere in any form.
Dim seschk As New Class1 - this code is required to create an instance of the class created in Class1.vb file. You can use the above code to create as many objects in multiple aspx file and use the functions present in class1.vb

Hope this helps, post back if you need further assistance.

Vincent Thomas
Bangalore
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
session and variable... badboy1 ASP.NET 3.5 Basics 1 August 3rd, 2008 09:14 AM
Can we get value of a session variable KamalRaturi ASP.NET 2.0 Professional 3 September 14th, 2006 03:33 PM
Session Variable youyou_hym Dreamweaver (all versions) 4 January 20th, 2005 11:48 AM
Session variable anuradha80 General .NET 3 November 4th, 2004 12:39 AM
Session variable mrideout BOOK: Beginning ASP.NET 1.0 1 August 12th, 2004 07:01 PM



All times are GMT -4. The time now is 10:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.