Solved

How to clone a session variable when openning a new window in the C# ASP.net?

Posted on 2004-04-15
10
868 Views
Last Modified: 2012-06-27

Let say i have 2 session variables: Val1, Val2; and 2 pages: page1, page2 (Page2 is opened when clicking on the link on the page1).

I want that the Val1 is shared between 2 pages but Val2 is separated. It means that if the page2's Val2 is changed in the page2 will not effect the page1's Val2. At the begining, the value of the Val2 in 2 pages should be the same.

How can i do that? Any idea is welcome.

Thank you in advance!
Giang.
0
Comment
Question by:giangdt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 10831386
when you open a new window from an existing all session objects are shared between the windows, so obviously you can not use one session colletion with different items it
what you can do is to create a new session object that is accessable only for the second windo
for example:
in the Page1 create Session["Val1"] and Session["Page1Val2"]
before opening the new window create Session["Page2Val2"] = Session["Page1Val2"]
and in the Page2 modifying the Session["Page2Val2"] object
if you keep in session datatable or something simillar you have to clone it by copy() method

HTH
B..M
0
 

Author Comment

by:giangdt
ID: 10831573
Hi,

Thank you.

But my problem is that the Val2 must is well-known, if not others will not get its value. All pages will submit to a controller, this controller will get the Val2's value to do the thing. So it depends on which page is submited the Controller will get the different value from the Val2.

Any one can help?

Giang.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10831603
so create the items like
"pagename" + standartkey

then when you want to get a value from the session collection just get the page that is submitted the data add as suffix the key and you can get the correct value
HTH
B..M
0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

Author Comment

by:giangdt
ID: 10831654
Hi,

So what will happen if there are more than 2 pages (page2) are opened from the page1? They will have the same session item!?

Giang.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10831676
you will have Val1 - for page1, page2, page3 ( page2 and page3 are opened from page1 )
and page2Val2 and page3Val2

B..M
0
 

Author Comment

by:giangdt
ID: 10831709

But if i have 2 opened page2s. And each page2 set the different value? What will be happen? The last change of the Val2 will effect the previous change in the another page2.

Giang.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10831735
giangdt, there are a lot of ways for searching for what page is currently opened
two of the easiest are:
send this info trhough the query string
create session object "pageID"
open the new window
create a hidden field in your page2 and set it's value to pageID value
dispose Session["pageID"] so if you open another page2 Session["pageID"] will have different value

B..M
0
 

Author Comment

by:giangdt
ID: 10831814
Hi mmarinov,

Can you tell me more details about pageID. What for?
If it will be added to the Val2 key(to make a difference), in this case how can i set the pageID so that this one is always unique? How can Controller know about the session item (pageID is dynamic)?


Thank you,
Giang.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 50 total points
ID: 10832050
the simple example is to generate GUID
so before open the page2->generate GUID->add created guid to session["PageID"]->open page2->in page2 controller get "PageID" item from the Session object->write somewhere this guid, for example in a hidden field-> dispose session["PageID"]-> Create session[GUID+"page2"]->in page2 work with the new created session

B..M
0
 

Author Comment

by:giangdt
ID: 10905583

Thank you mmarinov

Giang.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question