473,769 Members | 3,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Objects not maintaining values

I have created a container class and instantiated it in one of my pages. I
fill the object on page load when not on a postback. On a button click i
want to do somethign with the values in that object, but on my button event
being reached the object is now empty.

private Visitor VisitorObj = new Visitor();
protected Label label1;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
VisitorObj.GetV isitorDetails() ; //loads object here
}
}

private void UpdateButton_Cl ick(object sender, System.EventArg s e)
{
label1.Text = VisitorObj.Visi torID; //object is now empty though!!!
}

Any idea why the values in this object aren't being maintained across
postback but contents of the form on the page is.

MattC
Nov 18 '05 #1
3 1224
CT
You need to save your object between server round trips, possibly in the
Session object. The content of the controls on your Web form are by default
saved using view state.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"MattC" <m@m.com> wrote in message
news:uG******** ******@TK2MSFTN GP10.phx.gbl...
I have created a container class and instantiated it in one of my pages. I
fill the object on page load when not on a postback. On a button click i
want to do somethign with the values in that object, but on my button
event
being reached the object is now empty.

private Visitor VisitorObj = new Visitor();
protected Label label1;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
VisitorObj.GetV isitorDetails() ; //loads object here
}
}

private void UpdateButton_Cl ick(object sender, System.EventArg s e)
{
label1.Text = VisitorObj.Visi torID; //object is now empty though!!!
}

Any idea why the values in this object aren't being maintained across
postback but contents of the form on the page is.

MattC

Nov 18 '05 #2
Carsten,

Thanks for your reply.

Oddly though I have a Database class that wraps up some of the functionality
of ADO.NET and that maintains details such as then connection string set in
the SqlConnection object. This database class is stored within my Visitor
Object.

I thought that as my Visitor object was created at the server side once its
values are set they would remain set through round-trips. Or am i
misunderstandin g ASP.NET a bit here :S

thanx

MattC

"CT" <ca******@spamm ersgoawaydotnet services.biz> wrote in message
news:Ou******** ******@TK2MSFTN GP09.phx.gbl...
You need to save your object between server round trips, possibly in the
Session object. The content of the controls on your Web form are by default saved using view state.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"MattC" <m@m.com> wrote in message
news:uG******** ******@TK2MSFTN GP10.phx.gbl...
I have created a container class and instantiated it in one of my pages. I fill the object on page load when not on a postback. On a button click i want to do somethign with the values in that object, but on my button
event
being reached the object is now empty.

private Visitor VisitorObj = new Visitor();
protected Label label1;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
VisitorObj.GetV isitorDetails() ; //loads object here
}
}

private void UpdateButton_Cl ick(object sender, System.EventArg s e)
{
label1.Text = VisitorObj.Visi torID; //object is now empty though!!!
}

Any idea why the values in this object aren't being maintained across
postback but contents of the form on the page is.

MattC


Nov 18 '05 #3
> I thought that as my Visitor object was created at the server side once
its
values are set they would remain set through round-trips. Or am i
misunderstandin g ASP.NET a bit here :S
Hi Matt,

ASP.Net works in an HTTP environment. This means that each browser request
takes place "in a vacuum" so to speak. There is no link between one browser
Request and another as far as the web server is concerned. An HTTP Request
is received, handled, and then forgotten. This is why ASP.Net leverages such
objects as Session, which puts a cookie on the client, so that the browser
"identifies " itself with each new Request (or PostBack), and the Server
Session memory that belongs to that browser instance can be re-assigned to
that Request. ViewState is another mechanism for helping the server to
"remember" information from the last Request, by storing the values of
various Server Controls in a hidden form field in the client HTML. The form
posts the hidden field back to the server, which can then rebuild objects
based upon the values posted back.

In other words, with each Page Request, all server-side objects in that Page
must be re-built from scratch, and populated with any old/new information
sent from the browser with the Request.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"MattC" <m@m.com> wrote in message
news:u9******** ******@TK2MSFTN GP11.phx.gbl... Carsten,

Thanks for your reply.

Oddly though I have a Database class that wraps up some of the functionality of ADO.NET and that maintains details such as then connection string set in the SqlConnection object. This database class is stored within my Visitor
Object.

I thought that as my Visitor object was created at the server side once its values are set they would remain set through round-trips. Or am i
misunderstandin g ASP.NET a bit here :S

thanx

MattC

"CT" <ca******@spamm ersgoawaydotnet services.biz> wrote in message
news:Ou******** ******@TK2MSFTN GP09.phx.gbl...
You need to save your object between server round trips, possibly in the
Session object. The content of the controls on your Web form are by default
saved using view state.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"MattC" <m@m.com> wrote in message
news:uG******** ******@TK2MSFTN GP10.phx.gbl...
I have created a container class and instantiated it in one of my
pages. I fill the object on page load when not on a postback. On a button
click
i want to do somethign with the values in that object, but on my button
event
being reached the object is now empty.

private Visitor VisitorObj = new Visitor();
protected Label label1;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
VisitorObj.GetV isitorDetails() ; //loads object here
}
}

private void UpdateButton_Cl ick(object sender, System.EventArg s e)
{
label1.Text = VisitorObj.Visi torID; //object is now empty though!!!
}

Any idea why the values in this object aren't being maintained across
postback but contents of the form on the page is.

MattC



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1779
by: Robert Zurer | last post by:
My architecture is, (ala Fowler PoEAA) Presentation Layer | Service Layer | Problem Domain (My Business Objects are held in memory) | Persistence Layer
6
10625
by: M.Kamermans | last post by:
I have an XSLT script that has to operate on some particularly nasty XML to turn it into a SQL databse, but 'entries' in the XML aren't actually unique, so their unique identifier is useless. I need to somehow create crosslinked tables using the XSLT, but can only do this by maintaining a counter for each line I write. Is there a way to create a proxy 'increment' function that lets me maintain a counter variable? - Mike Kamermans
6
1737
by: pnp | last post by:
I have two objects AA and AB that derive from object A. These two objects have common atts that they inherit from object A but also some of their own. I have a pointer to an AA object and i would like to turn it to a pointer to an AB object, but maintaining the common information of these objects, such as the atts for example. How can I do this?
2
2009
by: Chris | last post by:
Hi, I am building a single webform/webpage asp.net application using VB.NET. I have created lots of classes for this web application. On page load I use a facade controller pattern class to perform all my initial class object instaniations using sub new() procedures I'm using this project to learn the ins and outs of OOA and OOD, so instead of doing everything in code behind pages I have lots of objects now created
161
7881
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
1
1466
by: Mike | last post by:
Hi All, Is there a good book or paper on conceptualizing Winforms as objects? In object-oriented programming I don't find it diffiucult to see "student", "person", or "car" as objects, but I do have problems conceptualizing a "form" and controls on forms as objects and how they fit together. Is there anything specifically on dealing with forms while maintaining the OO model and design in C#? Thanks much,
27
2568
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the Standard is saying that "object is a region of storage", I deduce from that that literal constants aren't objects because they may not be alocated as regions of storage in the memory.
16
1864
rpnew
by: rpnew | last post by:
Hello friends.... I'm developing one project in PHP-MySql on FC4..... I'm facing a problem here at one place. Let me describe it.... I've one page in php on which i'm generating a table containing checkboxes for option. These options have suboptions. User need to chose these options and suboptions. with suboption they are getting textboxes in which they can enter values for suboptons. When they submit the form i need to get all these data...
167
8345
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.