Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2006, 03:26 PM
Authorized User
 
Join Date: Aug 2006
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
 
Old September 12th, 2006, 03:35 PM
Wrox Author
 
Join Date: Oct 2005
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."
 
Old September 12th, 2006, 03:57 PM
Authorized User
 
Join Date: Aug 2006
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
 
Old September 13th, 2006, 04:53 AM
Authorized User
 
Join Date: Sep 2006
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





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





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