473,803 Members | 3,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class questions

I have an employee class - in my page, when it loads, it gets all the
employee data, including the employee Number.
I have
Dim emp As New Employee (at the top of the page, so it's global to the page)
emp.empno=Datar eader("empno") - and yes, it does get populated, correctly,
at page Load

Here's what I need, and isn't working:
I have a button on that page, which does a Server.Transfer to another page,
using that number, so I do something like this:
Server.Transfer ("secondpage.as px?empno=" & emp.empno, False) - I've tried
True also

however, at this point, emp.empno shows as '0' - not the real number

Is this the correct way to use class properties?
How long is a (Public) property like this available in the page?
What am I missing?

Oct 4 '07 #1
3 1192
Hi,
How long is a (Public) property like this available in the page?
Only while the page is rendering. When the page postsback you will no
longer have your object.
What am I missing?
To store data across postbacks you need to use something like
ViewState, or Session.

Eg.
If Not IsPostback Then
emp.empno=Datar eader("empno")
ViewState["empno"] = emp.empno
Else
emp.empno=ViewS tate["empno"]
End if

*Controls* preserve their state via the ViewState, which is why you
may have expected your object to also store it's state.

Jim

Oct 4 '07 #2
You can try to pass your info in the Context Object, that might work ???

HttpContext.Cur rent.Items.Add( "empno",emp.emp no)


<jd*******@gmai l.comwrote in message
news:11******** **************@ r29g2000hsg.goo glegroups.com.. .
Hi,
>How long is a (Public) property like this available in the page?

Only while the page is rendering. When the page postsback you will no
longer have your object.
>What am I missing?

To store data across postbacks you need to use something like
ViewState, or Session.

Eg.
If Not IsPostback Then
emp.empno=Datar eader("empno")
ViewState["empno"] = emp.empno
Else
emp.empno=ViewS tate["empno"]
End if

*Controls* preserve their state via the ViewState, which is why you
may have expected your object to also store it's state.

Jim

Oct 4 '07 #3
On Oct 4, 7:33 pm, jdlwri...@gmail .com wrote:
Hi,
How long is a (Public) property like this available in the page?

Only while the page is rendering. When the page postsback you will no
longer have your object.
What am I missing?

To store data across postbacks you need to use something like
ViewState, or Session.

Eg.
If Not IsPostback Then
emp.empno=Datar eader("empno")
ViewState["empno"] = emp.empno
Else
emp.empno=ViewS tate["empno"]
End if

*Controls* preserve their state via the ViewState, which is why you
may have expected your object to also store it's state.

Jim

Another option would be to create a label on your page which is
invisible (visible=false) :
On page_load:
if not page.ispostback then
HiddenLabel.tex t=emp.empno
end if

On button click:
Server.Transfer ("secondpage.as px?empno=" & HiddenLabel.tex t, False)

As Jim said, Controls preserve their viewstate so storing the Emp.
Number in a Label Control will preserve it for future postbacks.
Session variables would also work but you have to remember that if
your user opens up 10 browser windows, they will all share the same
sesison variables. So if you use session("EmpNum ber")=1 in one browser
window, session("EmpNum ber") will be 1 in ALL of the browser windows.
If you are using querystrings to send data (which allow multiple
browser windows), session variables will probably not work well for
you.

IfThenElse suggested the HTTPContext.Ite ms collection which is also
useful, but has its own caveats.The HTTPContext is only available
while the request is being processed. So if you add the Employee
object to the collection on the Submit button click, the Context
colelction will be available on the next page (only if you use
server.transfer ). But once you are on the next page, you will need to
save that employee information somewhere else because once that page
loads, the HTTPContext is dumped. So if your user were to refresh the
second page, your code would have no way of recovering the Employee
object if it was only stored in the HTTPContext.Ite ms collection.

HTH,

-E

Oct 5 '07 #4

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

Similar topics

4
3918
by: Sebastian Faust | last post by:
Hi, I have 4 questions related to templates. I wanna do something like the following: template<typename T> class Template { public: Template_Test<T>()
4
2167
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I want to send that dataset to another class module. At first it seems that the "object oriented"...
3
1335
by: alexhong2001 | last post by:
When design a class, should always make it "derivable" as a base class? Is there really a situation that the designed class not "derivable"? When should make a member "protected"? Only when allowing the derived class(es) directly access it? Should destructor always be virtual? Thanks for your comments!
16
3533
by: Merlin | last post by:
Hi Been reading the GOF book and started to make the distinction between Class and Interface inheritance. One question though: Do pure abstract classes have representations? (data members?) What about abstract classes? Should abstract classes have a destructor and or constructor? What about pure abstract classes?
6
1420
by: John Lee | last post by:
Hi, I was trying to find an elegant way of implementing/modelling the following scenario: student, borrower, reference and cosigner are all human beings - we would think to create a person base class and then create one class for each of the person type inheriting from person class - student is "IS-A" person, ... but there is chances that the student and the borrower will be the same person, how could we implement this in C#?
4
1169
by: Robert W. | last post by:
I'm thinking of building a complex data model with a number of nested classes but need to know something first. To simplify my question, let me present you this sample data model MainClass Questions (collection) Question (class) Text (property) Answers (collection) Answer (class)
6
2122
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
4
2150
by: alisaee | last post by:
plz check what i have made wrong what is requierd her is to creat class queue and class stack and run the push,pop operation . #include<iostream.h> #include<conio.h> #include<stdio.h> class stack { public:
11
2407
by: anongroupaccount | last post by:
What measures should be taken to avoid this sort of thing? class Base { }; class Derived1 : public Base { private: int i, j, k;
19
1652
by: Michael | last post by:
Hi, typedef std::vector<Vehicle* VehicleList; Vehicle is a UDT, or a class. Why is Vehicle* not just Vehicle in < >. Which one is better and why? If you could explain it by laying out some codes, it would be highly appreciated! Thanks in advance, Michael
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
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...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9121
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...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4275
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
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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.