Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Passing data

Reply
Thread Tools

Passing data

 
 
Ludwig
Guest
Posts: n/a
 
      04-09-2007
I have a user control news.ascx that lists news items, and it has
add/edit/delete linkbuttons.

This user control is on the default.aspx page together with other user
controls.

When the edit linkbutton for a news item is clicked, it redirects to
another page news.aspx, the news user control is also on this page.

Question: when the user clicks the edit linkbutton in the user control
on the default.aspx page, the data of the corresponding news item
should be passed to the control on the news.aspx page. What is the
best way to do that?

I was thinking of using the Session to store this data; but maybe
there's a better way?

Thanks for the suggestions!

--
Ludwig
http://www.coders-lab.be
 
Reply With Quote
 
 
 
 
Jon Paal [MSMD]
Guest
Posts: n/a
 
      04-09-2007
http://msdn2.microsoft.com/en-us/lib...w7(vs.71).aspx





"Ludwig" <ludwig.stuyck(remove)@telenet.be> wrote in message news(E-Mail Removed)...
>I have a user control news.ascx that lists news items, and it has
> add/edit/delete linkbuttons.
>
> This user control is on the default.aspx page together with other user
> controls.
>
> When the edit linkbutton for a news item is clicked, it redirects to
> another page news.aspx, the news user control is also on this page.
>
> Question: when the user clicks the edit linkbutton in the user control
> on the default.aspx page, the data of the corresponding news item
> should be passed to the control on the news.aspx page. What is the
> best way to do that?
>
> I was thinking of using the Session to store this data; but maybe
> there's a better way?
>
> Thanks for the suggestions!
>
> --
> Ludwig
> http://www.coders-lab.be



 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      04-09-2007


When I have a need like this, I use a custom " data store keeper " to
persist the info.
Before I go into that, think of it as just a fancy Session object wrapper.

I also create a specific (serializable) object used for this. Instead of
putting 3 (seperate) strings and ints in the Session, I create a mini object
specifically for passing info from default.aspx to news.aspx.

public class NewsEditArgs
--int NewsItemID
--string Something Else

Then I put this in the Server memory, ~with a specific key.

As soon as the other page (news.aspx) runs, I pull it out (remove it) and
use it on the news.aspx page.

This is so I don't accidently orphan records there.

I wrote one of these:
10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/


This is so I have a very good .Add and .Remove method (to avoid orphans).

However, if this is a "one page away" scenario, then look here
http://msdn2.microsoft.com/en-us/lib...01(VS.71).aspx
and at the other mentioned MS article.






"Ludwig" <ludwig.stuyck(remove)@telenet.be> wrote in message
news(E-Mail Removed)...
> I have a user control news.ascx that lists news items, and it has
> add/edit/delete linkbuttons.
>
> This user control is on the default.aspx page together with other user
> controls.
>
> When the edit linkbutton for a news item is clicked, it redirects to
> another page news.aspx, the news user control is also on this page.
>
> Question: when the user clicks the edit linkbutton in the user control
> on the default.aspx page, the data of the corresponding news item
> should be passed to the control on the news.aspx page. What is the
> best way to do that?
>
> I was thinking of using the Session to store this data; but maybe
> there's a better way?
>
> Thanks for the suggestions!
>
> --
> Ludwig
> http://www.coders-lab.be



 
Reply With Quote
 
Ludwig
Guest
Posts: n/a
 
      04-10-2007
On Mon, 9 Apr 2007 14:18:00 -0400, "sloan" <(E-Mail Removed)> wrote:

>
>
>When I have a need like this, I use a custom " data store keeper " to
>persist the info.
>Before I go into that, think of it as just a fancy Session object wrapper.
>
>I also create a specific (serializable) object used for this. Instead of
>putting 3 (seperate) strings and ints in the Session, I create a mini object
>specifically for passing info from default.aspx to news.aspx.
>
>public class NewsEditArgs
> --int NewsItemID
> --string Something Else
>
>Then I put this in the Server memory, ~with a specific key.
>
>As soon as the other page (news.aspx) runs, I pull it out (remove it) and
>use it on the news.aspx page.
>
>This is so I don't accidently orphan records there.
>
>I wrote one of these:
>10/24/2005
>Web Session Wrapper for storing and retrieving objects
>http://sholliday.spaces.live.com/blog/
>
>
>This is so I have a very good .Add and .Remove method (to avoid orphans).
>
>However, if this is a "one page away" scenario, then look here
>http://msdn2.microsoft.com/en-us/lib...01(VS.71).aspx
>and at the other mentioned MS article.
>


Thank you! I'll look into it! PS - what do you mean with orphan
records?

--
Ludwig
http://www.coders-lab.be
 
Reply With Quote
 
Ludwig
Guest
Posts: n/a
 
      04-10-2007
On Mon, 9 Apr 2007 14:18:00 -0400, "sloan" <(E-Mail Removed)> wrote:

>
>
>When I have a need like this, I use a custom " data store keeper " to
>persist the info.
>Before I go into that, think of it as just a fancy Session object wrapper.
>
>I also create a specific (serializable) object used for this. Instead of
>putting 3 (seperate) strings and ints in the Session, I create a mini object
>specifically for passing info from default.aspx to news.aspx.
>
>public class NewsEditArgs
> --int NewsItemID
> --string Something Else
>
>Then I put this in the Server memory, ~with a specific key.
>
>As soon as the other page (news.aspx) runs, I pull it out (remove it) and
>use it on the news.aspx page.
>
>This is so I don't accidently orphan records there.
>
>I wrote one of these:
>10/24/2005
>Web Session Wrapper for storing and retrieving objects
>http://sholliday.spaces.live.com/blog/
>
>
>This is so I have a very good .Add and .Remove method (to avoid orphans).
>
>However, if this is a "one page away" scenario, then look here
>http://msdn2.microsoft.com/en-us/lib...01(VS.71).aspx
>and at the other mentioned MS article.
>


Remark concerning your code: the instance in the datastore is a static
variable, so this means that it stays in memory on application level,
not session.... so it will be even if the session has ended. Is that
intended?

--
Ludwig
http://www.coders-lab.be
 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      04-11-2007

By orphan, I mean....
I put a value into the Session object. I use it. But it just "hangs out
there" because I didn't remove it.

Like I go to news.aspx, and read the object out of the Session... and
populate the values in news.aspx.
Then I go to a totally different place in my web app, never needing that
item I put in .Session again.
It just hangs out, taking up unnecessary resources.


The static thing. This was just the way you do a singleton in asp.net.

http://www.google.com/search?hl=en&q...t%22+singleton

Hmmm. You bring up an interesting point.
But even though its a static method, way down deep in the .GetInstance is

m_singletonInstance =
(WebSessionDataStore)System.Web.HttpContext.Curren t.Session[SESSION_OBJECT_G
UID];

So that part is Session/User Specific.

I do know I've had great success with it, in a multi user environment.

PS

Hints:
On a "login" , I usually clear the cache...........and also on a "logout".
What I mean is that when a user is verified, I go ahead an just make sure I
do a .Clear() , just in case the SessionID got stuck.

Sometimes the SessionID doesn't reset, even when you call Session.Abandon.

If the user clicks a logout button, I just call the .Clear() to make sure
there isn't something in Session memory orphaned.

That's kinda why I really like the Wrapper, I have control of when I need an
item, when I need to .Remove it, and when I need to wipe out everything.
Without a bunch of riddled Session object code throughout.

ids.Clear() is the method to call.


Below is my new 2.0 version. With a little extra check about the SessionID

You'll notice I have a IDataStore.
I also have a "WeakReference" implementation of this Interface.
You use a WeakReference, when you kinda want to cache stuff, but if there is
a big load on the server, the object gets released.
Aka, if the server is under load, and I cached up a list of departments or
something, the WeakReference will say "this isn't that important, release
it".
But the code below means "I need that object to be there no matter what".
I have a SimpleFactory that I throw a enum at, to get the 2 different
versions.


using System;
using System.Collections.Generic;
using System.Text;

namespace GranadaCoder.CachingFramework
{

[Serializable]
public class WebSessionDataStore //: IDataStore
{

//Guid ensures that uniqueid that won't be duplicated by accident
private const string SESSION_OBJECT_GUID =
"ABCABCAB-3754-4074-A007-051F9B64CA9E";

private static WebSessionDataStore _singletonInstance ;//= null;
private Dictionary<string, object> _memoryStore ;//= null;

private static string _sessionId = string.Empty;

#region Singleton Area

private WebSessionDataStore()
{
this._memoryStore = new Dictionary<string, object>();
}

/// <summary>
/// Singleton representing WebSessionDataStore.
/// </summary>
/// <returns></returns>
public static WebSessionDataStore GetInstance()
{
if (null != System.Web.HttpContext.Current)
{
if (null != System.Web.HttpContext.Current.Session)
{

bool resetSession = false;


if (System.Web.HttpContext.Current.Session.IsNewSessi on)
{
resetSession = true;
}

if
(System.Web.HttpContext.Current.Session.SessionID. ToUpper() !=
_sessionId.ToUpper())
{
resetSession = true;
}


if (resetSession)
{
_singletonInstance = null; //Its a new Session, to
blow away the singleton, so a new one is created.
}
else
{
if (null !=
System.Web.HttpContext.Current.Session[SESSION_OBJECT_GUID])
{
_singletonInstance =
(WebSessionDataStore)System.Web.HttpContext.Curren t.Session[SESSION_OBJECT_G
UID];
}

}


}
}

if (null == _singletonInstance)
{
_singletonInstance = new WebSessionDataStore();
System.Web.HttpContext.Current.Session[SESSION_OBJECT_GUID]
= _singletonInstance;
_sessionId =
System.Web.HttpContext.Current.Session.SessionID;//set the sessionId//



}
return _singletonInstance;

}

#endregion


#region IDataStore Members

/// <summary>
/// Removes all objects in the DataStore.
/// </summary>
public void Clear()
{
_memoryStore.Clear();
}

/// <summary>
/// Adds an object with the specified key.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The object to be added.</param>
public void Add(string key, object value)
{
if (_memoryStore.ContainsKey(key))
{
_memoryStore.Remove(key);
}

_memoryStore.Add(key, value);
}


//The next method doesn't do anything
////// public void AddNotRemovable(string key, object value)
////// {
////// this.Add( key, value );
////// }

/// <summary>
/// Removes the object using the specified key.
/// </summary>
/// <param name="key">The key used originally used to Add the item
to the DataStore.</param>
/// <returns></returns>
public object Remove(string key)
{
// see
http://java.sun.com/j2se/1.4.2/docs/...va.lang.Object)
// for java method, which returns the object you removed, in
case
// you want to do something with it

object returnObject = null;
if (null != this._memoryStore)
{
if (_memoryStore.ContainsKey(key))
{
returnObject = this._memoryStore[key];
_memoryStore.Remove(key);
}

}
return returnObject;
}

/// <summary>
/// Gets the <see cref="Object"/> with the specified key.
/// </summary>
/// <value></value>
public object this[string key]
{
get
{
if(this._memoryStore.ContainsKey(key))
{
if (null != _memoryStore[key])
{
return _memoryStore[key];
}
}
return null;
}
}

/// <summary>
/// Gets the number of items in the DataStore.
/// </summary>
/// <value>The size.</value>
public int Size
{
get
{
if (null != _memoryStore)
{
return _memoryStore.Count;
}
return 0;
}
}

#endregion
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array from FORTRAN to C then passing it within C andReturning it to FORTRAN deadpickle C Programming 1 11-07-2010 02:38 PM
Passing parameters to an executable vs. passing them to a server Ramon F Herrera C++ 8 09-13-2009 02:48 AM
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
Passing by const & and returning a temp vs passing by value and returningit Victor Bazarov C++ 25 03-23-2005 04:24 PM
Passing large data between forms, different apps terry ASP .Net 1 07-07-2003 06:05 PM



Advertisments