|
Thanks so much for the great example, Dave. I did not consider something like this. It looks like a very workable solution for calling static methods, but my real goal is to persist data in objects between calls to different pages and to do that I cannot use static classes since I have to instantiate data.
I thought about it alot and I think the best approach is to serialize the data in an XML data island between page calls. Then I can pick it up on the next page, de-serialize it, and move on.
Thanks again.
Adam
|
|
|
|
|
You are correct, the data must be stored somewhere. I generally use a database, but any storage method would work.
The idea in my example would be that CodeLayer.myProperties.myInt; would actually do the XML de-serialization in the property's get accessor. It just makes accessing those values very simple when you get to the page level...
- Dave
|
|
|
|
|
Why are you using Server.Transfer? Do you really need all of the viewstate and posted data from one page to be sent to the other? That can be pretty inefficient.
Create a class file in your web project. I would probably put it in its own namespace and then for each page that needs to use the class, add a using statement for that namespace.
What other objects do you need to instantiate and where do those classes live? What kind of persistence are you thinking of? Persisting in memory is usually not a good idea as that doesn't scale very well. You might want to do some research on some design patterns like the domain object model. Then you can look for an ORM (Object relational mapper) that will help you get your objects into and out of a database.
|
|
|
|
|
I put a class file in my project and put it in its own namespace and it is accessible to every page, but I really need access to the data in objects that I instantiate. The data I need must persist for the life of the applicaiton. It is kind of like a wizard app where I am accumulating data page to page for final submission at the end. This is only a 3 month project so I want to keep it simple since the timelines are a bit tight.
I thought about it alot and I think the best approach is to serialize the data in an XML data island between page transfers. Then I can pick it up on the next page, de-serialize it, and move on.
Thanks for your help.
Adam
|
|
|
|
|
namespace Ashwin {
public class Global : System.Web.HttpApplication, ICacheManager {
protected void Application_Start(object sender, EventArgs e) {
//Load the cache for the first time.
ReloadCache("All");
}
protected void Application_End(object sender, EventArgs e) {
//Cleanup anything that we left if we left anything using the SubmitReport.asmx
/*string tempPath = Server.MapPath("TempData");
if (System.IO.Directory.Exists(tempPath))
System.IO.Directory.Delete(tempPath, true);*/
}
/// <summary>
/// When the session starts.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_Start(object sender, EventArgs e) {
UserSession session = new UserSession(Request);
try {
LoggedInUserInfo liui = session.Login();
// if user successfully logged in
// then store in Session cache
if(liui != null) {
CacheManager.SetCache("loggedInUser", CacheManager.cacheTypeEnum.Session, liui, this);
// get the top 10 Read reports in last 30 days i.e. one month
Report report = new Report();
IList list = report.GetTopReadReport(10, DateRangeEnum.OneMonth, ReportClassificationEnum.All, liui.User.UserId);
CacheManager.SetCache("TopReadReport", CacheManager.cacheTypeEnum.Session, list, this);
FillCache("SavedSearches");
}
} catch(Exception exc) {
Exception LastException = exc;
Session["LastException"] = LastException;
ErrorDetail ed = new ErrorDetail();
RecordError recordError = new RecordError();
recordError.Credentials = new System.Net.NetworkCredential(Util.GetConfigValue("WebServicesLogin"), Util.GetConfigValue("WebServicesPwd"));
recordError.PreAuthenticate = true;
ed.applicationName = "Ashwin20";
ed.browserVersion = Request.ServerVariables["HTTP_USER_AGENT"];
ed.errorUrl = Request.Url.ToString();
ed.note = LastException.Message;
ed.stackTrace = LastException.StackTrace;
ed.userName = Util.GetSimpleUsername(User);
//recordError.ReportError(ed);
Response.Redirect("ErrorPage.aspx");
}
}
/// <summary>
/// Fill in the cached value and return the list.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private IList FillCache(string key) {
CacheManager.cacheTypeEnum application = CacheManager.cacheTypeEnum.Application;
CacheManager.cacheTypeEnum session = CacheManager.cacheTypeEnum.Session;
Org org = new Org();
SpecificSubject specificSubject = new SpecificSubject();
BusinessUnit busisnessUnit = new BusinessUnit();
OptinTitle optinTitle = new OptinTitle();
GeoArea geoArea = new GeoArea();
Function funtion = new Function();
Cop cop = new Cop();
Prod prod = new Prod();
DateRange dateRange = new DateRange();
SecurityGroup securityGroup = new SecurityGroup();
SecurityGroupInfo sgi = new SecurityGroupInfo();
Report report = new Report();
IList list = null;
// These tables hardly changes so we are going to store them
// in the application cache using the CacheManager.
if (key == "All" || key == "SecurityGroup") {
list = securityGroup.GetSecurityGroup();
CacheManager.SetCache("SecurityGroup", application, list, this);
}
if (key == "All" || key == "Organizations") {
list = org.GetOrg();
CacheManager.SetCache("Organizations", application, list, this);
}
if (key == "All" || key == "KeyCompetencies") {
list = specificSubject.GetSpecificSubject();
CacheManager.SetCache("KeyCompetencies", application, list, this);
}
if (key == "All" || key == "BusinessUnits") {
list = busisnessUnit.GetBusUnit();
CacheManager.SetCache("BusinessUnits", application, list, this);
}
if (key == "All" || key == "Levels") {
list = optinTitle.GetOptinTitle();
CacheManager.SetCache("Levels", application, list, this);
}
if (key == "All" || key == "Regions") {
list = geoArea.GetGeoArea();
CacheManager.SetCache("Regions", application, list, this);
}
if (key == "All" || key == "Functions") {
list = funtion.GetFunc();
CacheManager.SetCache("Functions", application, list, this);
}
if (key == "All" || key == "CoPs") {
list = cop.GetCop();
CacheManager.SetCache("CoPs", application, list, this);
}
if (key == "All" || key == "Sectors") {
list = prod.GetSector();
CacheManager.SetCache("Sectors", application, list, this);
}
if (key == "All" || key == "DateRange") {
list = dateRange.GetDateRange();
CacheManager.SetCache("DateRange", application, list, this);
}
// Cache Top 10 Readers and Top 10 Authors
// get the top 10 Readers in last 3 months
if(key == "All" || key == "TopReader") {
list = report.GetTopReaders(10, DateRangeEnum.ThreeMonths,"");
CacheManager.SetCache("TopReader",
CacheManager.cacheTypeEnum.Application, list, this);
}
// get the top 10 Authors in last 12 months i.e. one year
if(key == "All" || key == "TopAuthor") {
list = report.GetTopAuthors(10, DateRangeEnum.OneYear, "");
CacheManager.SetCache("TopAuthor",
CacheManager.cacheTypeEnum.Application, list, this);
}
// Get submitted report count in last 30 days from the database
if(key == "All" || key == "SubmittedReportCount") {
int submittedReportCount = 0;
Report ri = new Report();
// Call DB Method
// to get total reports submitted in last 30 days
submittedReportCount = ri.GetReportsSubmittedCount();
CacheManager.SetCache("SubmittedReportCount",
CacheManager.cacheTypeEnum.Application, submittedReportCount, this);
}
// Get report count in last 30 days from the content monitor service
if(key == "All" || key == "ViewedReportCount") {
int viewedReportCount = 0;
// Call Content Monitor WebService
// to get total viewed report count in last 30 days
MonitorReportService.ReportService reportService
= new MonitorReportService.ReportService();
reportService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
reportService.PreAuthenticate = true;
viewedReportCount = reportService.GetApplicationAccessCount
(Util.GetConfigValue("ApplicationName"), 30);
CacheManager.SetCache("ViewedReportCount",
CacheManager.cacheTypeEnum.Application, viewedReportCount, this);
}
if (key == "SavedSearches") {
// list of the user’s Saved searches using new Isubscribe webservice
//Get the saved Searches for the current user
iSubscribeService.iSubscribeWebService isubscribeService = new iSubscribeService.iSubscribeWebService();
isubscribeService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
isubscribeService.PreAuthenticate = true;
LoggedInUserInfo liui = Session["loggedInUser"] as LoggedInUserInfo;
list = isubscribeService.GetAllSavedSearchesByApplication
(liui.User.UserId,
int.Parse(Util.GetConfigValue("ApplicationId")));
CacheManager.SetCache("SavedSearches", session, list, this);
}
return list;
}
#region ICacheManager Methods
/// <summary>
/// Reload the cache.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object ReloadCache(string key) {
object obj = null;
obj = FillCache(key);
return obj;
}
#endregion
}
}
---- Cache Manager ----
namespace Ashwin.BLL.Controls {
/// <summary>
/// Summary description for CacheManager.
/// </summary>
public class CacheManager {
//Hash table to hold all values
private static readonly Hashtable theCache = Hashtable.Synchronized(new Hashtable());
private static readonly CacheManager m_manager = new CacheManager();
/// <summary>
/// The types of cache we will deal with
/// </summary>
public enum cacheTypeEnum { Application, Session };
/// <summary>
/// Returns the singleton instance of the cache manager
/// </summary>
public static CacheManager Manager {
get { return m_manager; }
}
/// <summary>
/// Returns the cached value for the given key.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object GetCache(string key) {
object ret;
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
//Look in Application cache
ret = HttpContext.Current.Application[key];
if (ret == null) { //Look in Session
ret = HttpContext.Current.Session[key];
if (ret != null) {
cacheInfo.Type = cacheTypeEnum.Session;
cacheInfo.Value = ret;
}
} else {//Application
cacheInfo.Type = cacheTypeEnum.Application;
cacheInfo.Value = ret;
}
return ret;
}
/// <summary>
/// Adds the value to the cache
/// </summary>
/// <param name="key"></param>
/// <param name="type"></param>
/// <param name="theValue"></param>
/// <param name="container"></param>
public static void SetCache(string key, cacheTypeEnum type, object theValue, ICacheManager container) {
switch (type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = theValue; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = theValue;
break;
}
//Add this to our hashtable
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
cacheInfo.Type = type;
cacheInfo.Value = theValue;
cacheInfo.Container = container;
theCache[key] = cacheInfo;
}
/// <summary>
/// Returns an IList of CacheInfo objects representing all cached items
/// </summary>
/// <returns></returns>
public static IList GetAllCache() {
ArrayList list = new ArrayList();
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
list.Add(cacheInfo);
}
return list;
}
/// <summary>
/// Clear the Cached Item
/// </summary>
/// <param name="key">The key to clear</param>
public static void ClearCacheReload(string key) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
cacheInfo.Value = cacheInfo.Container.ReloadCache(key);
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
cacheInfo.Value = null;
break;
}
theCache[key] = cacheInfo;
}
}
/// <summary>
/// Clear All Items in the cache
/// </summary>
public static void ClearCache() {
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
break;
}
cacheInfo.Value = null;
theCache[key] = cacheInfo;
}
}
}
}
}
Please help
|
|
|
|
|
Please write your code within code block & describe more
|
|
|
|
|
Please could you elaborate on what the problem is precisely. That's alot of code to wade through without knowing the bit to focus on.
|
|
|
|
|
No one is going to look through this useless unformatted drivel. Format the code using the pre tags, i.e. "code block" and only include what is necessary, not everything.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi,
In my project i am using "ajaxToolkit:CalendarExtender" with Textbox.
If i am entering invalid date like 12/56/2010(mm/dd/yyyy), that time i am getting proper validation message but after getting the msg the textbox.text is getting changed into 12/31/1969 default. In the code no where i wrriten the code like this.
But when see the view source code of the page, textbox value contains invalid date.
This is strange thing that i am facing. Anybody knows the root cause of this please tell me.
The code is
<asp:textbox id="txtDate" cssclass="input10Char small" runat="server" maxlength="10">
<ajaxtoolkit:calendarextender
="" id="DateCalendarExtender" cssclass="CalendarControl" runat="server" popupposition="Right" format="MM/dd/yyyy" popupbuttonid="CalendarButton" targetcontrolid="txtDate">
Thanks in Advance for your solution.
|
|
|
|
|
Hi all,
I am facing a problem using update panel.
I have an update panel in a page with UpdateMode="Conditional"
the update panel contains a grid view.I want to fetch a particular row's value from that grid view and put it in to a label which is out side the update panel on select index change event.My code is running.I can debug it.But label's value is not changing.on the select index change method of the grid view.
|
|
|
|
|
Hi,
The label should be added inside the UpdatePanel in order to be updated.
Regards,
Jamil
|
|
|
|
|
souravghosh18 wrote: label which is out side the update panel
Here is the problem.
You have two solutions for the same.
1. Put the Label control with in the same UpdatePanel of Gridview.
2. Put Lable control into a different updatepanel ( Say updatepanel2 ), Change the UpdateMode="Conditional" . On Gridview Selected Index Change Event along with set value to lable, you need to do UpdatePanel2.Update()
Hope this will help you
|
|
|
|
|
Abhijit Jana wrote: need to do UpdatePanel2.Update()
Not necessary. Using a postback trigger is all that is needed.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Place the label in an update panel and set a postback trigger for the grid.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi all
I am working on property website. we want to display properties on sale in google map using asp.Net. How to do that?
Thanks for any suggestions?.............
|
|
|
|
|
|
what about code
|
|
|
|
|
Have you even opened the link? Have you even tried a cursory search? Would you like someone to write this for you?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
ya i write a code in which when i click on property a pop window opens
anyway i got the javascript code
if u wana know then check following link
Sorry to bother u....
thanks for your help anyway.....................
|
|
|
|
|
These are forums for discussion on ways to implement solutions to problems, not full out code solutions. You want that, you'll need to pay for it at www.rentacoder.com or similar.
If you've actually tried to do this already and are stuck then I apologize, please elaborate on what part you're stuck on and what you have tried already.
|
|
|
|
|
You do know that google maps already has a properties for sale option built in right? Pull up a map and under the "more" menu, real estate is the last check box.
|
|
|
|
|
i have a problem. i want to use session in thread class but it return null in parent that is the page class. can any one have any idea how to handle this .
thanx in advance.
amirzada
|
|
|
|
|
It might help to show a little of what you are doing, but you should be able to access it via HttpContext.Session
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi All,
I am looking for suggestions;
These are my requirements;
1)I need a chat to be integrated to my website(ASP) where in the admins(we have around 5) will able to see other users(around 60) but the other users will be able to see only the admins.
The basic idea is the users should not chat with each other.
2)I am ready to pay for this component.
3)I checked eTalkUp.The issue is i dont know whether i can customize this chat as per my requirement (1).They will only answer technical details once we pay up.I dont want to pay up if my specific requirement wont be met.
4)Does anyone in this forum have any experience with eTalkUp?.Will we be able to implement my requirements in eTalkUp.
5)Is their any other chat component i can buy or download and integrate to my website that will meet my requirement (1).
|
|
|
|
|
Hi all, I'm running Asp.Net 2.0 Application. I have only one instance of the application in the Server. There is an occasional problem where data for one logged in user gets the data from another logged in user in the Mail Content.
Please suggest me solution.
Thanks in Advance.
Thanks & Regards,
Rathika Krishnavelu
|
|
|
|
|