By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Passing variables in ASP.Net

BezerkRogue
P: 68
This is the most fundamental action I am sure, but I can't seem to make it happen.

I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have some scripts that run at the server for the form so I can't disable that statement. I followed Microsoft's instructions(I know..not the best thing to do) but still can't get the variables to pass.

I created a class and set up an @reference statement, created property declarations to get the variables in the source page and set the server.transfer instruction to pass to the next page. The results....nothing. nada, zilch.

Can anyone help me out here?

Here's the inline script for the source page:
'Variable declaration for class object to encapsulate variables for page transfer
Dim fp As FirstPageClass

'Read property for Shift variable
Public ReadOnly Property Shift() As String
Get
Return SHIFT_ID.Text
End Get
End Property

'Read property for Date variable
Public ReadOnly Property SelDate() As String
Get
Return OccDate.SelectedDate
End Get
End Property

'Command string to pass the variables to next page
Sub cmdSubmit_OnClick(ByVal Sender As Object, ByVal e As EventArgs)
Server.Transfer("ChangeMPRep.aspx")

Here's the inline script for the receiving page:
Dim fp As FirstPageClass
Sub Page_Load()
Dim fp
If Not IsPostBack Then
fp = CType(Context.Handler, FirstPageClass)
End If
End Sub
Oct 22 '07 #1
Share this Question
Share on Google+
6 Replies


Plater
Expert 5K+
P: 7,872
You could use the Session object for this?
Oct 22 '07 #2

BezerkRogue
P: 68
Is this the correct code to put in the VB file

Source page:

Session.Add("SelDate", OccDate.SelectedDate)
Session.Add("Shift", SHIFT_ID)

Receiving page: (Displaying variable in labels)

lblSelDate = Session("SelDate")
lblShift = Session("Shift")

I think that I might be missing something in between.
Oct 22 '07 #3

Plater
Expert 5K+
P: 7,872
That looks good, it's important to test for null though.
Expand|Select|Wrap|Line Numbers
  1. if (Session("SelDate") !=null)
  2. {
  3.    lblSelDate = Session("SelDate")
  4. }
  5. if (Session("Shift") !=null)
  6. {
  7.    lblShift = Session("Shift")
  8. }
  9.  
Oct 22 '07 #4

BezerkRogue
P: 68
Got it. Would using context work as well? I am limited on server resources and this is shaping up to be a very busy site.

context.items.add("name", value)
Oct 22 '07 #5

Plater
Expert 5K+
P: 7,872
I am unfamiliar with "context" objects. Sorry.
Oct 22 '07 #6

nateraaaa
Expert 100+
P: 663
Got it. Would using context work as well? I am limited on server resources and this is shaping up to be a very busy site.

context.items.add("name", value)
You could also pass the variable as a querystring value.
page.aspx?id=variablevalue

Nathan
Oct 22 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.