Wednesday, March 21, 2012
persist a class over a session - concept
i have a class, for example :"CustomerClass" , with a set of public
properies like CustNr,CustName,CustEmail ...
The class is initialised when the session is started.
What is the best way to persist the property values?
Must each property stored in a separate session, and by each access read the
valueof the session - or exist a better way...
thankshttp://spaces.msn.com/sholliday/ 10/24/2005
Check my Blog.
This is a wrapper... to store objects in a session, ... not just properties
of objects.
..
"Xavier" <Xavier@.discussions.microsoft.com> wrote in message
news:DA11396B-EC6B-44BD-BD1C-2ACE2EE491B0@.microsoft.com...
> hello,
> i have a class, for example :"CustomerClass" , with a set of public
> properies like CustNr,CustName,CustEmail ...
> The class is initialised when the session is started.
> What is the best way to persist the property values?
> Must each property stored in a separate session, and by each access read
the
> valueof the session - or exist a better way...
> thanks
persist a class over a session - concept
i have a class, for example :"CustomerClass" , with a set of public
properies like CustNr,CustName,CustEmail ...
The class is initialised when the session is started.
What is the best way to persist the property values?
Must each property stored in a separate session, and by each access read the
valueof the session - or exist a better way...
thankshttp://spaces.msn.com/sholliday/ 10/24/2005
Check my Blog.
This is a wrapper... to store objects in a session, ... not just properties
of objects.
...
"Xavier" <Xavier@.discussions.microsoft.com> wrote in message
news:DA11396B-EC6B-44BD-BD1C-2ACE2EE491B0@.microsoft.com...
> hello,
> i have a class, for example :"CustomerClass" , with a set of public
> properies like CustNr,CustName,CustEmail ...
> The class is initialised when the session is started.
> What is the best way to persist the property values?
> Must each property stored in a separate session, and by each access read
the
> valueof the session - or exist a better way...
> thanks
Persist a stack across PostBacks?
stack) across PostBacks?
TIA!
- WarrenYou can put pretty much anything, as long as it's Serializable, in the
page's ViewState and then retrieve it after a postback:
ViewState["Thing"] = myThing;
// later after postback...
myThing = (Thing)ViewState["Thing"];
There's some overhead associated with this because the ViewState is
downloaded as part of the page's html and uploaded again as part of the
request. If it's a large object you're better off saving it in the Session.
-Jason
Warren J. Hairston wrote:
> Can anyone point me toward a solution for persisting non-controls (i.e.: a
> stack) across PostBacks?
> TIA!
> - Warren
>
Persist a database connection across postbacks
I'm a new comer to web development as well as asp.net. So when
i fired up my first database driven page, i knew i had a problem of not
having a persistent database connection across postbacks. I tried to
piggyback the connection object to application object and it didn't
work. Well i do know that you ASP.net experts have a default way of
handling this scenario. Please enlighten me.Godwin Burby wrote:
> Hi All,
> I'm a new comer to web development as well as asp.net. So when
> i fired up my first database driven page, i knew i had a problem of not
> having a persistent database connection across postbacks. I tried to
> piggyback the connection object to application object and it didn't
> work. Well i do know that you ASP.net experts have a default way of
> handling this scenario. Please enlighten me.
Just my two-penneth, and may not be the answer you're looking for:
Create a function that creates/sets up your connection. Whenever you
need to interact with the database, call this function, do your data
work, and close the connection. Let the .NET framework worry about
connections and connection pooling.
This may at first sound counterintuitive, and up until a few months
ago, I was going along the route of "create one connection, share it
around, and keep it open". I had a stubborn application that was taking
four hours to perform some processing (admittedly, I was abusing
ASP.NET quite considerably to get this working). I switched around to
opening connections when I needed them, doing the db work, and closing
the connection. The same process then started taking less than ten
minutes.
The Open/Use/Close approach should definitely scale better than either
a) one connection for the whole application, or b) one connection per
session. (a) has problems because you have to do a lot of locking
around every db interaction to make sure no-one else is using it. (b)
can fail if the user opens a second browser window and fires off two db
related tasks simultaneously.
Damien
Hi,
Objects are destroyed every time page is rendered to client browser ..
so you need to create connection again..
One thing you can do is connection pooling but still you need to open a
connection from your application
..
"Godwin Burby" <godwinburby@.gmail.com> wrote in message
news:1142395833.438452.265750@.z34g2000cwc.googlegroups.com...
> Hi All,
> I'm a new comer to web development as well as asp.net. So when
> i fired up my first database driven page, i knew i had a problem of not
> having a persistent database connection across postbacks. I tried to
> piggyback the connection object to application object and it didn't
> work. Well i do know that you ASP.net experts have a default way of
> handling this scenario. Please enlighten me.
>
Thank you Damien for sharing your hardearned knowledge.
Thanx Hussain. I choose to open and close connection each time.
Persist a database connection across postbacks
I'm a new comer to web development as well as asp.net. So when
i fired up my first database driven page, i knew i had a problem of not
having a persistent database connection across postbacks. I tried to
piggyback the connection object to application object and it didn't
work. Well i do know that you ASP.net experts have a default way of
handling this scenario. Please enlighten me.Godwin Burby wrote:
> Hi All,
> I'm a new comer to web development as well as asp.net. So when
> i fired up my first database driven page, i knew i had a problem of not
> having a persistent database connection across postbacks. I tried to
> piggyback the connection object to application object and it didn't
> work. Well i do know that you ASP.net experts have a default way of
> handling this scenario. Please enlighten me.
Just my two-penneth, and may not be the answer you're looking for:
Create a function that creates/sets up your connection. Whenever you
need to interact with the database, call this function, do your data
work, and close the connection. Let the .NET framework worry about
connections and connection pooling.
This may at first sound counterintuitive, and up until a few months
ago, I was going along the route of "create one connection, share it
around, and keep it open". I had a stubborn application that was taking
four hours to perform some processing (admittedly, I was abusing
ASP.NET quite considerably to get this working). I switched around to
opening connections when I needed them, doing the db work, and closing
the connection. The same process then started taking less than ten
minutes.
The Open/Use/Close approach should definitely scale better than either
a) one connection for the whole application, or b) one connection per
session. (a) has problems because you have to do a lot of locking
around every db interaction to make sure no-one else is using it. (b)
can fail if the user opens a second browser window and fires off two db
related tasks simultaneously.
Damien
Hi,
Objects are destroyed every time page is rendered to client browser ..
so you need to create connection again..
One thing you can do is connection pooling but still you need to open a
connection from your application
...
"Godwin Burby" <godwinburby@.gmail.com> wrote in message
news:1142395833.438452.265750@.z34g2000cwc.googlegr oups.com...
> Hi All,
> I'm a new comer to web development as well as asp.net. So when
> i fired up my first database driven page, i knew i had a problem of not
> having a persistent database connection across postbacks. I tried to
> piggyback the connection object to application object and it didn't
> work. Well i do know that you ASP.net experts have a default way of
> handling this scenario. Please enlighten me.
Thank you Damien for sharing your hardearned knowledge.
Thanx Hussain. I choose to open and close connection each time.
persist Checkbox state in datagrid
i have a datagrid control in a page with checkbox column and paging option.
i selected some checkbox and going to next page or prev page, if i come back to the same page
the checkbox is not checked in that page.
so how to persist that checked item throughout the datagrid?
can any one help me with codingWhen the page is changed the DataGrid is data bound again therefore repopulating everything from the data source. This means any changes made client-side are lost. Save the changes made to the data source before data binding.
DJ
Friday, March 16, 2012
Persist data in XML data island
on the cleint side. The user should be able to scroll through the
records, modify any or all fields in any or all records, add records,
and delete records.
As far as I can see, there are a couple of ways to implement this. I
could persist the original data island and create a duplicate data
island that the user would modify. When the modifications were
complete, I could post back both XML snippets and compare them to see
what has changed.
Alternatively, I was thinking about using the DiffGram idea, where
each change would add an xml element to an xml snippet that would
indicate what item was changed, added, deleted, etc.
I know that I am not the first person to want to use this type of
technique, so I was hoping that there is something built into the .Net
framework to help with the management of the data. Ideally, I would
like to do something like serialize a dataset to XML, send it to the
client as an XML data island, have them manipulate it, repost it, and
then turn it "magically" into a batch update to the dataset on the
server side. Is that possible, or do I have to roll my own solution?
Thanks.
PatIf you read the XML back into a dataset, then you can use .getchanges on the
datatable to get only the changed rows. Send this back to the server in a
dataset. One easy way to do this is to use web services on the server.
"Pat Alessi" <pwalessi1@.hotmail.com> wrote in message
news:5de67752.0405250947.7f526dc4@.posting.google.c om...
> I want to use an XML data island to display editable records to a user
> on the cleint side. The user should be able to scroll through the
> records, modify any or all fields in any or all records, add records,
> and delete records.
> As far as I can see, there are a couple of ways to implement this. I
> could persist the original data island and create a duplicate data
> island that the user would modify. When the modifications were
> complete, I could post back both XML snippets and compare them to see
> what has changed.
> Alternatively, I was thinking about using the DiffGram idea, where
> each change would add an xml element to an xml snippet that would
> indicate what item was changed, added, deleted, etc.
> I know that I am not the first person to want to use this type of
> technique, so I was hoping that there is something built into the .Net
> framework to help with the management of the data. Ideally, I would
> like to do something like serialize a dataset to XML, send it to the
> client as an XML data island, have them manipulate it, repost it, and
> then turn it "magically" into a batch update to the dataset on the
> server side. Is that possible, or do I have to roll my own solution?
> Thanks.
> Pat
So, I could create a dataset, serialize it and send it down to the
client. Then, on the client side, I could bind it to some controls,
let the user add, delete, and modify records. Then, on repost, I
should convert the data back into a dataset, and call .getchanges? I
don't see how getchanges would work without having the original
dataset to compare the new dataset to?
How could I implement this with web services without posting the
information back to the server for every change?
Pat
"Rick Spiewak" <rickspiewak@.mindspring.com> wrote in message news:<#BJ7SftQEHA.3420@.TK2MSFTNGP11.phx.gbl>...
> If you read the XML back into a dataset, then you can use .getchanges on the
> datatable to get only the changed rows. Send this back to the server in a
> dataset. One easy way to do this is to use web services on the server.
> "Pat Alessi" <pwalessi1@.hotmail.com> wrote in message
> news:5de67752.0405250947.7f526dc4@.posting.google.c om...
> > I want to use an XML data island to display editable records to a user
> > on the cleint side. The user should be able to scroll through the
> > records, modify any or all fields in any or all records, add records,
> > and delete records.
> > As far as I can see, there are a couple of ways to implement this. I
> > could persist the original data island and create a duplicate data
> > island that the user would modify. When the modifications were
> > complete, I could post back both XML snippets and compare them to see
> > what has changed.
> > Alternatively, I was thinking about using the DiffGram idea, where
> > each change would add an xml element to an xml snippet that would
> > indicate what item was changed, added, deleted, etc.
> > I know that I am not the first person to want to use this type of
> > technique, so I was hoping that there is something built into the .Net
> > framework to help with the management of the data. Ideally, I would
> > like to do something like serialize a dataset to XML, send it to the
> > client as an XML data island, have them manipulate it, repost it, and
> > then turn it "magically" into a batch update to the dataset on the
> > server side. Is that possible, or do I have to roll my own solution?
> > Thanks.
> > Pat
Don't bind to the XML, re-create the dataset. Then you can do getchanges
against the modified table, re-create a dataset with just the changes,
and send that back up to the server.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
persist data in the form
button to trigger another asp.net web form for lookup purpose. My problem is
when the user choose data from the lookup form and back to input data, the
data in the input data form was refreshed and become blank. How can I
persist those data in the input data form??
Million thankshttp://msdn.microsoft.com/msdnmag/i...te/default.aspx
"Grey" <erickwyum@.i-cable.com> wrote in message
news:O7xHjuIlEHA.592@.TK2MSFTNGP11.phx.gbl...
> There is a ASP.NET web form for user input data, user can also click one
> button to trigger another asp.net web form for lookup purpose. My problem
is
> when the user choose data from the lookup form and back to input data, the
> data in the input data form was refreshed and become blank. How can I
> persist those data in the input data form??
> Million thanks
persist data in the form
button to trigger another asp.net web form for lookup purpose. My problem is
when the user choose data from the lookup form and back to input data, the
data in the input data form was refreshed and become blank. How can I
persist those data in the input data form'
Million thankshttp://msdn.microsoft.com/msdnmag/i...te/default.aspx
"Grey" <erickwyum@.i-cable.com> wrote in message
news:O7xHjuIlEHA.592@.TK2MSFTNGP11.phx.gbl...
> There is a ASP.NET web form for user input data, user can also click one
> button to trigger another asp.net web form for lookup purpose. My problem
is
> when the user choose data from the lookup form and back to input data, the
> data in the input data form was refreshed and become blank. How can I
> persist those data in the input data form'
> Million thanks
>
Persist DataTable Values
I have a DataTable that I have defined Globally. I populate this datatable
dynamically with file/folder information that I read directly from the
server. I use this datatable information to bind mainly to a DataGrid, but
I would also like it to persist for the duration that I have a particular
page open. I seem to be losing this data either thru postbacks or by the
way I have coded it. Does anyone have any suggestions on how I can keep
this datatable in memory? TIA
--
Best regards
Paul Perot
President
Perot Solutions
perotsolutions@dotnet.itags.org.earthlink.net
(770) 565 - 9151
(678) 852 - 7789 (c)You began by saying that the DataTable is "defined Globally." What does that
mean? Global to what? Obviously, it isn't truly global, or you wouldn't be
asking how to persist it. For example, if it was global to the Application
(in Application Cache, for example), you wouldn't need to persist it in any
other way. It would be truly global.
I only asked that to get you thinking along these lines, hopefully so that
this situation would not rear its ugly head again for you. The issue here is
scope. And a good understanding of ASP.Net scope is what is needed to
resolve it and any future issues of scope that may arise.
I suspect that by "defined Globally" you mean that you declared a variable
with Page scope, that is, defined in your Page class as a Field or Property
of your Page class, not inside a Method. However, the scope of such a
variable is global to only a single Page instance, and each Request for a
Page creates a new Page instance. A PostBack will not see the value of a
variable declared in a previous instance of this Page class, as the variable
will be re-initialized with the initialization of the Page class.
As you've defined the requirement that this variable be global to all
instances of this Page class (within the context of a single initial Request
and the related group of PostBacks), you could declare it as static (Shared
in VB.Net) in the Page class, or, if you want it re-initialized with each
non-PostBack (initial Request), you could put it into the Page's ViewState
or in Session. If you put it into ViewState, the size of it may affect the
time it takes for the Page to load in the browser (ViewState being a hidden
form field in the HTML form). The advantage of ViewState is that the
variable will disappear as soon as a different Page is Requested. If you use
Session, the Page will have to re-initialize the Session value when it is
Requested via non-PostBack (initial Request).
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Paul Perot" <perotsolutions@.earthlink.net> wrote in message
news:CyjCb.332$X97.100@.newsread2.news.atl.earthlin k.net...
> Hi All:
> I have a DataTable that I have defined Globally. I populate this
datatable
> dynamically with file/folder information that I read directly from the
> server. I use this datatable information to bind mainly to a DataGrid,
but
> I would also like it to persist for the duration that I have a particular
> page open. I seem to be losing this data either thru postbacks or by the
> way I have coded it. Does anyone have any suggestions on how I can keep
> this datatable in memory? TIA
> --
> Best regards
> Paul Perot
> President
> Perot Solutions
> perotsolutions@.earthlink.net
> (770) 565 - 9151
> (678) 852 - 7789 (c)
Persist data in XML data island
on the cleint side. The user should be able to scroll through the
records, modify any or all fields in any or all records, add records,
and delete records.
As far as I can see, there are a couple of ways to implement this. I
could persist the original data island and create a duplicate data
island that the user would modify. When the modifications were
complete, I could post back both XML snippets and compare them to see
what has changed.
Alternatively, I was thinking about using the DiffGram idea, where
each change would add an xml element to an xml snippet that would
indicate what item was changed, added, deleted, etc.
I know that I am not the first person to want to use this type of
technique, so I was hoping that there is something built into the .Net
framework to help with the management of the data. Ideally, I would
like to do something like serialize a dataset to XML, send it to the
client as an XML data island, have them manipulate it, repost it, and
then turn it "magically" into a batch update to the dataset on the
server side. Is that possible, or do I have to roll my own solution?
Thanks.
PatIf you read the XML back into a dataset, then you can use .getchanges on the
datatable to get only the changed rows. Send this back to the server in a
dataset. One easy way to do this is to use web services on the server.
"Pat Alessi" <pwalessi1@.hotmail.com> wrote in message
news:5de67752.0405250947.7f526dc4@.posting.google.com...
> I want to use an XML data island to display editable records to a user
> on the cleint side. The user should be able to scroll through the
> records, modify any or all fields in any or all records, add records,
> and delete records.
> As far as I can see, there are a couple of ways to implement this. I
> could persist the original data island and create a duplicate data
> island that the user would modify. When the modifications were
> complete, I could post back both XML snippets and compare them to see
> what has changed.
> Alternatively, I was thinking about using the DiffGram idea, where
> each change would add an xml element to an xml snippet that would
> indicate what item was changed, added, deleted, etc.
> I know that I am not the first person to want to use this type of
> technique, so I was hoping that there is something built into the .Net
> framework to help with the management of the data. Ideally, I would
> like to do something like serialize a dataset to XML, send it to the
> client as an XML data island, have them manipulate it, repost it, and
> then turn it "magically" into a batch update to the dataset on the
> server side. Is that possible, or do I have to roll my own solution?
> Thanks.
> Pat
So, I could create a dataset, serialize it and send it down to the
client. Then, on the client side, I could bind it to some controls,
let the user add, delete, and modify records. Then, on repost, I
should convert the data back into a dataset, and call .getchanges? I
don't see how getchanges would work without having the original
dataset to compare the new dataset to?
How could I implement this with web services without posting the
information back to the server for every change?
Pat
"Rick Spiewak" <rickspiewak@.mindspring.com> wrote in message news:<#BJ7SftQEHA.3420@.TK2MSFT
NGP11.phx.gbl>...
> If you read the XML back into a dataset, then you can use .getchanges on t
he
> datatable to get only the changed rows. Send this back to the server in a
> dataset. One easy way to do this is to use web services on the server.
> "Pat Alessi" <pwalessi1@.hotmail.com> wrote in message
> news:5de67752.0405250947.7f526dc4@.posting.google.com...
Don't bind to the XML, re-create the dataset. Then you can do getchanges
against the modified table, re-create a dataset with just the changes,
and send that back up to the server.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Persist Javascript change to CssClass
Hi,
I have a panel in a repeater that has a Javascript Show/Hide that just changes the CSS Class on the Panel. I would like to persist the change to the CSS Class that is made by Javascript after a PostBack but i'm having no luck.
I've tried inheriting from asp:Panel and overriding theSaveViewState() andLoadViewState(), savingg the CssClass in the viewstate here but is doesn't persist and the default always appears on PostBack.
Can anyone help? Some example code is included below...
<asp:Repeater><ItemTemplate><asp:HyperLink> id="HyperLink2" runat="server">... HyperLink has a Javascript on it that changes the CSS Classon the Panel via the ID that is registered in code ...</asp:HyperLink><asp:Panel id="Panel1">"Panel1" Runat="server" CssClass="Hide"> ... Stuff In Here ...</asp:Panel></Itemtemplate></asp:Repeater>You could put the value in a hidden field and always read from it on the postback.
Thanks for the response...
could you elaborate on what you wrote?
How would I reference the hidden field? If you have the time could you give me an example?
no problem.
The hidden field in html would look like this <input type="hidden" runat="server" id="txtHiddenField"/>
To write to this field you would use this javascript code
var HiddenField = document.getElementById("txtHiddenField");
HiddenField.Value = "NameOfCSSClass";
Then on the postback you can read from it the same way
var HiddenField = document.getElementById(txtHiddenField");
HiddenField.Value will have "NameOfCSSClass";
Thank you very much for the help...
Got it working doing what you suggested...
What got me was the client side JavaScript wasn't changing the CSS class name in the client code on the browser so it wasn't registering as a change. It does change the client code when updating a hidden field via javascript which worked perfectly then on a postback...
Lovely
Persist Page Location
o scroll down a little to see them all. Incidentally the last control is a t
able control which allows you to add a new row dynamically upon clicking a l
ink button.
Because link button fires a postback, which is what is needed in order to ad
d the next row to the table it brings the user back to the top of the page a
fterwards.
I want the user to be back where they clicked on the link button at the bott
om of the page. I recall there is a setting or some easy way to do this but
for the life of me can not remember. Any help would be great!
-DemetriOn 8/4/2004 10:45 AM, Demetri wrote:
> I have an aspx page which has many controls. Just enough to cause the user
to scroll down a little to see them all. Incidentally the last control is a
table control which allows you to add a new row dynamically upon clicking a
link button.
> Because link button fires a postback, which is what is needed in order to
add the next row to the table it brings the user back to the top of the page
afterwards.
> I want the user to be back where they clicked on the link button at the bo
ttom of the page. I recall there is a setting or some easy way to do this bu
t for the life of me can not remember. Any help would be great!
>
SmartNavigation was the way to overcome some of this 'page viewing
state' problems in the browser, but I've heard it's buggy.
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Hi Demetri,
Have a look at Scott Guthrie's TechEd 2003 Black Belt Web Forms presentation
(http://www.scottgu.com) he coveres this scenario, under the title
"scrolling and postback".
Hope this helps,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights.
"Demetri" <Demetri@.discussions.microsoft.com> wrote in message
news:54F55A7E-B548-402A-BCF4-1DBFDD5FF9BE@.microsoft.com...
>I have an aspx page which has many controls. Just enough to cause the user
>to scroll down a little to see them all. Incidentally the last control is a
>table control which allows you to add a new row dynamically upon clicking a
>link button.
> Because link button fires a postback, which is what is needed in order to
> add the next row to the table it brings the user back to the top of the
> page afterwards.
> I want the user to be back where they clicked on the link button at the
> bottom of the page. I recall there is a setting or some easy way to do
> this but for the life of me can not remember. Any help would be great!
> --
> -Demetri
Persist object
I'm in need of some brainstormin help!
We have an object that we use in a number of places, both by User Controls
and Pages. This object is loaded everytime we need to use the piece of
functionality.
Example:
The user logs in and the object is loaded, the user then clicks a link to do
a task and again the object is loaded again.
What is the best way to persist the object? Session, cookie etc as it will
be used alot as the user uses the app.
Also, what are people thoughts about this, and it there any patterns that
may help?
Thanks all,
JonJon,
If it is an aspx or html page and is called with the same parameters or
without any parameters, it will be cached on the client side and will open
very fast. You will have to tell us more about the nature of the object to
hear other suggestions.
Eliyahu
"Jon" <Jon@.discussions.microsoft.com> wrote in message
news:7472A3B1-1802-4EB5-8E5D-BAC04F26185D@.microsoft.com...
> Hello all,
> I'm in need of some brainstormin help!
> We have an object that we use in a number of places, both by User Controls
> and Pages. This object is loaded everytime we need to use the piece of
> functionality.
> Example:
> The user logs in and the object is loaded, the user then clicks a link to
do
> a task and again the object is loaded again.
> What is the best way to persist the object? Session, cookie etc as it will
> be used alot as the user uses the app.
> Also, what are people thoughts about this, and it there any patterns that
> may help?
> Thanks all,
> Jon
Some ramblings,
if the object is loaded from server side state then I suggest making
all your pages (and controls?) extend from a base class (that you
create), this class would extend from System.web.UI.Page,
This class could load the object and set a property, which the derived
classes could access.
If the object is not to big then I'd recomend doing this each page
load, caching the object brings in added complexity,
If its a big object (or static for all users) then cache it, use the
session for user based objects and cache for static objects
In my experience though its best to load the object with each page
request
Eliyahu,
The object is data that is a collection class that we loop through to
create a tree (like Windows). This tree is not only used for navigation, but
also used in UserControls to help the user when carrying out some action,
like copying a file, specifying where to place a file etc.
The data help in the collection class rarely changes, but when we use it, we
always reload it and we were just thinking if that would be a performance
drag?
Thanks,
Jon
"Eliyahu Goldin" wrote:
> Jon,
> If it is an aspx or html page and is called with the same parameters or
> without any parameters, it will be cached on the client side and will open
> very fast. You will have to tell us more about the nature of the object to
> hear other suggestions.
> Eliyahu
> "Jon" <Jon@.discussions.microsoft.com> wrote in message
> news:7472A3B1-1802-4EB5-8E5D-BAC04F26185D@.microsoft.com...
> do
>
>
Jon,
If the collection is specific to a user session, the best place is the
session.
If it is application-wide, meaning it is the same for all users, a public
static variable will be good. You can also use application's Cache if you
want to be able to control the way how the object persists.
Eliyahu
"Jon" <Jon@.discussions.microsoft.com> wrote in message
news:1BE9F76D-8B0A-4A21-B65A-54057D8E4BE7@.microsoft.com...
> Eliyahu,
> The object is data that is a collection class that we loop through to
> create a tree (like Windows). This tree is not only used for navigation,
but
> also used in UserControls to help the user when carrying out some action,
> like copying a file, specifying where to place a file etc.
> The data help in the collection class rarely changes, but when we use it,
we
> always reload it and we were just thinking if that would be a performance
> drag?
> Thanks,
> Jon
> "Eliyahu Goldin" wrote:
>
open
to
Controls
to
will
that
Persist object
I'm in need of some brainstormin help!
We have an object that we use in a number of places, both by User Controls
and Pages. This object is loaded everytime we need to use the piece of
functionality.
Example:
The user logs in and the object is loaded, the user then clicks a link to do
a task and again the object is loaded again.
What is the best way to persist the object? Session, cookie etc as it will
be used alot as the user uses the app.
Also, what are people thoughts about this, and it there any patterns that
may help?
Thanks all,
JonJon,
If it is an aspx or html page and is called with the same parameters or
without any parameters, it will be cached on the client side and will open
very fast. You will have to tell us more about the nature of the object to
hear other suggestions.
Eliyahu
"Jon" <Jon@.discussions.microsoft.com> wrote in message
news:7472A3B1-1802-4EB5-8E5D-BAC04F26185D@.microsoft.com...
> Hello all,
> I'm in need of some brainstormin help!
> We have an object that we use in a number of places, both by User Controls
> and Pages. This object is loaded everytime we need to use the piece of
> functionality.
> Example:
> The user logs in and the object is loaded, the user then clicks a link to
do
> a task and again the object is loaded again.
> What is the best way to persist the object? Session, cookie etc as it will
> be used alot as the user uses the app.
> Also, what are people thoughts about this, and it there any patterns that
> may help?
> Thanks all,
> Jon
Some ramblings,
if the object is loaded from server side state then I suggest making
all your pages (and controls?) extend from a base class (that you
create), this class would extend from System.web.UI.Page,
This class could load the object and set a property, which the derived
classes could access.
If the object is not to big then I'd recomend doing this each page
load, caching the object brings in added complexity,
If its a big object (or static for all users) then cache it, use the
session for user based objects and cache for static objects
In my experience though its best to load the object with each page
request
Eliyahu,
The object is data that is a collection class that we loop through to
create a tree (like Windows). This tree is not only used for navigation, but
also used in UserControls to help the user when carrying out some action,
like copying a file, specifying where to place a file etc.
The data help in the collection class rarely changes, but when we use it, we
always reload it and we were just thinking if that would be a performance
drag?
Thanks,
Jon
"Eliyahu Goldin" wrote:
> Jon,
> If it is an aspx or html page and is called with the same parameters or
> without any parameters, it will be cached on the client side and will open
> very fast. You will have to tell us more about the nature of the object to
> hear other suggestions.
> Eliyahu
> "Jon" <Jon@.discussions.microsoft.com> wrote in message
> news:7472A3B1-1802-4EB5-8E5D-BAC04F26185D@.microsoft.com...
> > Hello all,
> > I'm in need of some brainstormin help!
> > We have an object that we use in a number of places, both by User Controls
> > and Pages. This object is loaded everytime we need to use the piece of
> > functionality.
> > Example:
> > The user logs in and the object is loaded, the user then clicks a link to
> do
> > a task and again the object is loaded again.
> > What is the best way to persist the object? Session, cookie etc as it will
> > be used alot as the user uses the app.
> > Also, what are people thoughts about this, and it there any patterns that
> > may help?
> > Thanks all,
> > Jon
>
Jon,
If the collection is specific to a user session, the best place is the
session.
If it is application-wide, meaning it is the same for all users, a public
static variable will be good. You can also use application's Cache if you
want to be able to control the way how the object persists.
Eliyahu
"Jon" <Jon@.discussions.microsoft.com> wrote in message
news:1BE9F76D-8B0A-4A21-B65A-54057D8E4BE7@.microsoft.com...
> Eliyahu,
> The object is data that is a collection class that we loop through to
> create a tree (like Windows). This tree is not only used for navigation,
but
> also used in UserControls to help the user when carrying out some action,
> like copying a file, specifying where to place a file etc.
> The data help in the collection class rarely changes, but when we use it,
we
> always reload it and we were just thinking if that would be a performance
> drag?
> Thanks,
> Jon
> "Eliyahu Goldin" wrote:
> > Jon,
> > If it is an aspx or html page and is called with the same parameters or
> > without any parameters, it will be cached on the client side and will
open
> > very fast. You will have to tell us more about the nature of the object
to
> > hear other suggestions.
> > Eliyahu
> > "Jon" <Jon@.discussions.microsoft.com> wrote in message
> > news:7472A3B1-1802-4EB5-8E5D-BAC04F26185D@.microsoft.com...
> > > Hello all,
> > > > I'm in need of some brainstormin help!
> > > > We have an object that we use in a number of places, both by User
Controls
> > > and Pages. This object is loaded everytime we need to use the piece of
> > > functionality.
> > > > Example:
> > > > The user logs in and the object is loaded, the user then clicks a link
to
> > do
> > > a task and again the object is loaded again.
> > > > What is the best way to persist the object? Session, cookie etc as it
will
> > > be used alot as the user uses the app.
> > > > Also, what are people thoughts about this, and it there any patterns
that
> > > may help?
> > > > Thanks all,
> > > > Jon
Persist search criteria
Hi friends,
I am designing a search page in which the user will select different options and search the results. In the search results page, I will place a button "Ammend Search" / "New Search". By clicking on that will redirect to search page. The search page must persist the prev search criteria. How can I do this?
If I use history.back(), it will work for times when there is no further postbacks to the results page. If there are some postbacks to the results page, its not working.
How can I do this?
Thanks in advance
There are couple of approaches.
1. Make your link a server sided hyperlink, upon the first time entering the page, set its url with the search parameters.
Something like
void Page_Load(...)
{
if(!Page.IsPostBack){
MyLink.NavigationUrl = "search.aspx?name="+Request["name"];
}
}
the link such will maintain the url in viewstate upon postback. Second step is of course, in your search page, if the parameters is in the url, you have to set them back on your search page.
2. Use Profile Service of ASP.NET 2.0. Before search is performed and go the result page, use Profile Object to remember what was entered and such upon coming back, everything will be there.
Just some thoughts.
another approach could be, that you can save the last search criteria in Session Object and can use it later when needed.
persist values from one postback to another
Not sure if the title makes sense but heres my dilemma. I have two
dropdownlist controls on a webform. I want to make sure that the first
dropdownlist control was clicked on and a value was selected. I want to check
in the second dropdownlist control that this has happened before processing
any info. I thought I would set a boolean in the selected event of the first
ddl control but when the event fires for the second ddl control the boolean
is set back to false due to the page reloading, I assume. How can I persist
that boolean value between postbacks? And for this scenario what is the best
way to achieve my goal if the way im describing is not the best?
Thanks,
JJTake a look at requiredFieldValidator and custom validator
The easiest way to handle this is to simply check and ensure the first
control is not set to index 0.
if(ddlFirstControl.SelectedIndex==0)
//code to indicate the user did not touch drop down 1
else
//code to process dropdown 2
If you want to persist a boolean (not necessary if the first drop down has
an invalid value, like "choose one"), you can store it in ViewState.
//in Drop down change event for the first drop down
ViewState("FirstControlChanged") = true;
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"JJ" wrote:
> Hi,
> Not sure if the title makes sense but heres my dilemma. I have two
> dropdownlist controls on a webform. I want to make sure that the first
> dropdownlist control was clicked on and a value was selected. I want to check
> in the second dropdownlist control that this has happened before processing
> any info. I thought I would set a boolean in the selected event of the first
> ddl control but when the event fires for the second ddl control the boolean
> is set back to false due to the page reloading, I assume. How can I persist
> that boolean value between postbacks? And for this scenario what is the best
> way to achieve my goal if the way im describing is not the best?
> Thanks,
> JJ
Persist tables controls
I don't know why all the controls of the Table class (server control)
has to be reconstructed for each page load. The MSDN said that it is
because the children controls are not the Table properties. But why
other controls like ListBox or DataGrid can persist their child
controls?
I'm very confused about this.
Thanks for any reply,
Nhat YenHi,
all non-controls are persisted via ViewState and they can be restored that
way. But controls do need to recreated on every request (and they then load
their own state indepedently after they have been created)
ListBox works so that it saves the state by calling SaveViewState of its
Items collection (ListItemCollection) which stores the items in key/value
sense. On postback items are loaded from ViewState and ListItemCollection
is reconstructed. E.g ListBox actually uses the similar procedure to
repopulate the collection. ListItems aren't controls so therefore ListBox
can work this way without controls "in the middle".
DataGrid can recreate the controls because they (child controls) are usually
specified in templates (or via columns). DataGrid stores the count of rows
which it uses to recreate the Items collection (by instantiating templates)
and then the child controls load their state independently after they've
been created. So basically DataGrid doesn't store the child controls but
recreates them on postback.
Basically you can't avoid recreating controls because control are themselves
responsible for storing their state. Also it would be terribly inefficient
tho store complete control instances to ViewState, therefore only control
state is stored and controls themselves are recreated.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Nhat Yen" <s2119205@.rmit.edu.vn> wrote in message
news:1d84a655.0402211915.5cfed176@.posting.google.c om...
> Hi everyone,
> I don't know why all the controls of the Table class (server control)
> has to be reconstructed for each page load. The MSDN said that it is
> because the children controls are not the Table properties. But why
> other controls like ListBox or DataGrid can persist their child
> controls?
> I'm very confused about this.
> Thanks for any reply,
> Nhat Yen
Thanks for very clear explanation Teemu, it help me a lot.
Again thank you!
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<erMHQre#DHA.3816@.tk2msftngp13.phx.gbl>...
> Hi,
> all non-controls are persisted via ViewState and they can be restored that
> way. But controls do need to recreated on every request (and they then load
> their own state indepedently after they have been created)
> ListBox works so that it saves the state by calling SaveViewState of its
> Items collection (ListItemCollection) which stores the items in key/value
> sense. On postback items are loaded from ViewState and ListItemCollection
> is reconstructed. E.g ListBox actually uses the similar procedure to
> repopulate the collection. ListItems aren't controls so therefore ListBox
> can work this way without controls "in the middle".
> DataGrid can recreate the controls because they (child controls) are usually
> specified in templates (or via columns). DataGrid stores the count of rows
> which it uses to recreate the Items collection (by instantiating templates)
> and then the child controls load their state independently after they've
> been created. So basically DataGrid doesn't store the child controls but
> recreates them on postback.
> Basically you can't avoid recreating controls because control are themselves
> responsible for storing their state. Also it would be terribly inefficient
> tho store complete control instances to ViewState, therefore only control
> state is stored and controls themselves are recreated.
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
>
> "Nhat Yen" <s2119205@.rmit.edu.vn> wrote in message
> news:1d84a655.0402211915.5cfed176@.posting.google.c om...
> > Hi everyone,
> > I don't know why all the controls of the Table class (server control)
> > has to be reconstructed for each page load. The MSDN said that it is
> > because the children controls are not the Table properties. But why
> > other controls like ListBox or DataGrid can persist their child
> > controls?
> > I'm very confused about this.
> > Thanks for any reply,
> > Nhat Yen
Thanks for very clear explanation Teemu, it help me a lot.
Again thank you!
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<erMHQre#DHA.3816@.tk2msftngp13.phx.gbl>...
> Hi,
> all non-controls are persisted via ViewState and they can be restored that
> way. But controls do need to recreated on every request (and they then load
> their own state indepedently after they have been created)
> ListBox works so that it saves the state by calling SaveViewState of its
> Items collection (ListItemCollection) which stores the items in key/value
> sense. On postback items are loaded from ViewState and ListItemCollection
> is reconstructed. E.g ListBox actually uses the similar procedure to
> repopulate the collection. ListItems aren't controls so therefore ListBox
> can work this way without controls "in the middle".
> DataGrid can recreate the controls because they (child controls) are usually
> specified in templates (or via columns). DataGrid stores the count of rows
> which it uses to recreate the Items collection (by instantiating templates)
> and then the child controls load their state independently after they've
> been created. So basically DataGrid doesn't store the child controls but
> recreates them on postback.
> Basically you can't avoid recreating controls because control are themselves
> responsible for storing their state. Also it would be terribly inefficient
> tho store complete control instances to ViewState, therefore only control
> state is stored and controls themselves are recreated.
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
>
> "Nhat Yen" <s2119205@.rmit.edu.vn> wrote in message
> news:1d84a655.0402211915.5cfed176@.posting.google.c om...
> > Hi everyone,
> > I don't know why all the controls of the Table class (server control)
> > has to be reconstructed for each page load. The MSDN said that it is
> > because the children controls are not the Table properties. But why
> > other controls like ListBox or DataGrid can persist their child
> > controls?
> > I'm very confused about this.
> > Thanks for any reply,
> > Nhat Yen
Persist Sorted List
Thanks
hello.
If the product class is serializable, then i think that you can easily build a classe which inherits from list<product> and implements the iserializable interface. here's an article about serialization in .net:
http://www.15seconds.com/issue/020903.htm
I need to find a clean way to persist it in the db, not a file.
Thanks,
Edgardo
hello.
well, it's almos the same thing. you'll just need to have a column which is capable of savings blobs. by the way, if you want to save the elements in text format, then use the xmlserializer
persist xml in class referenced in asp.net page
I have another class which is referenced in the asp.net page.
The first page load creates an instance of the class. In the class
are various methods which build up an xml file...ie create method
builds the
first root element, and other calls add elements and attributes to
this base root node.
The webpage has various buttons, dropdowns, and other controls which
when clicked on perform the various methods.
Now I could write the current XML to a filestore after each method in
my separate class file ie, Create root node, add elements, add
attributes, but I would rather persist an xmldocument object in the
class somehow.
However my asp.net page doesn't hold the properties of the first call
to the separate class into the second call. So if I instanciate my
class on the first page load, and don't recreate it on postback, if in
after CreateRoot() method called after the first button click, I call
an AddElement() method after another event, the xmldocument object
doesn't have its root node anymore.
Is there anyway a class can do this for an asp.net page, persist xml
between multiple postbacks, or is this by nature not possible due to
the fact that asp.net destroys all objects when it unloads?
Any clarification appreciated, I am attempting to build some
EnterpriseServices around the generation of Xml Template based
system...
Thanks,
yurpsIn article <984bebc3.0406220557.1044e41f@.posting.google.com>,
yurps@.yahoo.co.uk says...
> Is there anyway a class can do this for an asp.net page, persist xml
> between multiple postbacks, or is this by nature not possible due to
> the fact that asp.net destroys all objects when it unloads?
Look into the ViewState:
"Saving Web Forms Page Values Using View State"
http://tinyurl.com/2a8ns
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele