PC Review


Reply
Thread Tools Rate Thread

Class questions

 
 
Trust Me; I'm from the government
Guest
Posts: n/a
 
      4th Oct 2007
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=Datareader("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.aspx?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?



 
Reply With Quote
 
 
 
 
jdlwright@gmail.com
Guest
Posts: n/a
 
      5th Oct 2007
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=Datareader("empno")
ViewState["empno"] = emp.empno
Else
emp.empno=ViewState["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

 
Reply With Quote
 
IfThenElse
Guest
Posts: n/a
 
      5th Oct 2007
You can try to pass your info in the Context Object, that might work ???

HttpContext.Current.Items.Add("empno",emp.empno)




<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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=Datareader("empno")
> ViewState["empno"] = emp.empno
> Else
> emp.empno=ViewState["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
>



 
Reply With Quote
 
Elroyskimms
Guest
Posts: n/a
 
      5th Oct 2007
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=Datareader("empno")
> ViewState["empno"] = emp.empno
> Else
> emp.empno=ViewState["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.text=emp.empno
end if

On button click:
Server.Transfer("secondpage.aspx?empno=" & HiddenLabel.text, 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("EmpNumber")=1 in one browser
window, session("EmpNumber") 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.Items 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.Items collection.

HTH,

-E

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
2 C# Class's Questions deepak Microsoft ASP .NET 4 2nd Oct 2010 06:03 PM
SqlBulkCopy class questions... Jéjé Microsoft Dot NET Framework 0 14th Dec 2005 11:37 AM
Questions on HttpApplication class parez Microsoft ASP .NET 2 14th Oct 2005 06:26 PM
c# overriding class questions MattB Microsoft C# .NET 2 9th Jul 2004 04:02 PM
Using the pen class - Questions Tobias Froehlich Microsoft C# .NET 3 19th Sep 2003 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.