Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I define a dynamic session variable array? 1

Status
Not open for further replies.

Levin

Programmer
Feb 19, 2002
4
JP
Hi,all,

How can I define a dynamic session variable array in
asp.net?

Or, can I define a dynamic variable array in a web form?

I am now using web application project in vb.net to
develop asp.net. But I can't find a good method to
interchange variables across different procedures in a web
form.

Thanks for help,

 
Hey Levin,

So you're wondering how to create module level variables like you can do in a desktop vb app?

No prob. If you want to create a module level variable on the fly, all you have to do is put somewhere in your code behind:
Session("Whatever") = and whatever you want it to equal to.

A good practice is to declare any page level variables you will use in the page load around a

If Not Page.IsPostBack

End If

block, so that they won't get re-created on every postback.

Another option (which isn't as nice though) is to create hidden fields on your web form to store info, but I think the Session way is a bit cleaner.

If I totally misunderstood your question, let me know.

Jack
 
Jack,thanks for your reply.

I want to declare an array used in the page.
But if I declare the array in the

If Not Page.IsPostBack
...
End If

block, the array I declared can not be recognized.
I think the scope for the array is not for all the page , but only in the block.

Do you know how can I declare an array used for all the page?

Thanks,
 
Hey Levin,

I'm sorry, I totally didn't write what I meant. When I said:
A good practice is to declare any page level variables you will use in the page load around a

If Not Page.IsPostBack

End If

block, so that they won't get re-created on every postback.

What I really meant to say was:
A good practice is to declare any page level variables you will use in the page load around a

If Not Page.IsPostBack

End If

block, AND ASSIGN THEM TO A SESSION VARIABLE so that they won't get re-created on every postback.

So for what you want to do, in the array you would create the array and then set it to a session variable, all within that If Not Page.IsPostBack-End If block. This way, when your page posts back, that code won't fire (so you won't be recreating the array), and your session variable will be accessible from the entire page.

Let me know if you need anything else
:)

jack
 
It's helpful to me.
Thanks, Jack.

Levin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top