473,378 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

custom base classes

hello,

i understand the usefulness of having custom base classes when it
pertains to common methods or custom handling of events (say,
overriding all pages OnError and sending out an email of the
exception).

my question perstains to custom properties of a base class. say i write
a base class, and add two new properties to it (example only, not my
actual properties):

- CustomerID
- CustomerName

....would this make sense, if i wanted to be able to use those props
thru out the app ("this.CustomerID"), sorta like using Session
variables? or would it make more sense to just stick w/ Session?

i ask because i tried a test -- created those two new props in my base
class, and then in a page's OnLoad "if (!IsPostBack)" i assigned values
to them. however, on subsequent button events, the props were empty
because they were not assigned to via the OnLoad. hmm. i was hoping
they would retain state.

do i have the wrong idea about using custom props like this? or should
i just stick to using the Session? OR, would it be best to use the
Session only in OnInit, and assign it to these custom props?

just trying to figure the best practice.
thanks!
matt

Apr 6 '06 #1
4 1277
Hi Matt,

Each time a page request is made the ASP.NET Page object is recreated,
so any instance values that were set in the previous request will be
lost. It's possible to get around this by using static class
properties, however these will be lost when the application domain is
recycled, which happen by default every 29 hours, and whenever you
modify web.config. This approach is not considered best practice for
maintaining state across page requests.

Better approaches would be to use the Session object, cookies or the
viewstate, depending on your requirements. For maintaining
application-wide data, consider using a database or the Cache object
(in preference of the Application object). If you want to persist
state data for individual users, take a look at using ASP.NET 2.0
profiles.

Hope that helps,

Chris

Apr 6 '06 #2
thanks, chris.

i do wish to persist state data for individual users, however 2.0 is
not an option at this time.

im thinking..what about -- adding user properties to the base class,
and then set/get them via Session? this could be useful because if we
choose to move away from session to cookies, or viewstate, etc, we
could update it in one place, our base class population.. the consuming
applications would never see the change, since they still access
everything view "this.CurrentAssetID" (etc)... is this done?
thanks!
matt

Apr 6 '06 #3
Hi Matt,

That would certainly be an option and you could abstract the underlying
state technology in your getter and setter methods.

However, I think a better design would be to create a new "User" or
"Member" class to encapsulate all the data and behaviour associated
with a user. You could then use this to encapsulate your state logic.
This might be a more flexible approach and you could use your User
object from anywhere, including other business objects, without having
to worry about the lifetime or state of your Page object.

Good luck,

Chris

Apr 6 '06 #4
chris,

yes, for "User" type information, i think you are correct, that would
be a better approach.

my actual scenario is not for user-info, i just used it for an example
(poor choice). in this actual case, im concerned w/ application data --
which "asset group" the user is manipulating data for (via the app). i
thought it might make sense to this AssetID and AssetName to be stored
in the page base since it pertains to the app itself and not the user.
matt

Apr 6 '06 #5

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

Similar topics

0
by: Lefevre | last post by:
Hello I recently had troubles with a class inheritance hierarchy. I solved it, but it didn't satisfied me. I found the solution using this forum :) Actualy i found the following message...
4
by: Xavier | last post by:
Hi, I have a question, in a "dreaded diamond" situation, regarding the following code: ---- Begin code #include <iostream> using namespace std;
6
by: Ben Finney | last post by:
Howdy all, Okay, so Guido doesn't like Abstract Base Classes, and interfaces are the way of the future. But they're not here now, and I understand ABCs better. I want my modules to...
1
by: hansiman | last post by:
I have a site with two user types (user and admin) I'd like to add some code to one master base page (BasePageMater), and one user base page (BasePageUser) and one admin base page...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
0
by: hamstak | last post by:
I had developed a custom base page class for the 1.1 framework which I have now migrated to the 2.0 framework. I discovered that the new partial class system -- which appears to "automagically"...
0
by: =?Utf-8?B?VG9tIE1jTGVvZA==?= | last post by:
We are migrating an application from VS.NET 2003 to VS 2005. The client and server have many types passed via web services that are shared in common assemblies. In VS.NET 2003, we used a custom...
3
by: Juha Nieminen | last post by:
It occurred to me while developing an application: What happens if two (completely independent) base classes have the exact same virtual function, and then a derived class is derived from both,...
3
by: Rick | last post by:
One of the rules I have recommended for our new coding standard is as follows: "When overriding a base class virtual function, all overloads of that base class virtual function should also be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.