473,470 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1284
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...
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...
0
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...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.