 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 11th, 2009, 11:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> Since cache is session/user specific
This is not true; cache is application specific and is preferred over Application state because of its expiration policies and management.
Cheers,
Imar
|

December 11th, 2009, 12:25 PM
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Application context in asp.net web application
ok.
then can u please provide me with the way i can get back the cached data.
Please find the code below and let me know where is going wrong:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
objDataUtility.CreateConnection(true);
LoadMenu();
}
}
public Object LoadMenu()
{
Object oMenu = Application.Get("Menu");
if (oMenu == null)
{
DataTable dt = PopulateRootLevel();
PopulateNodes(dt, mnuMenu.Items);
Application.Add("Menu", mnuMenu.Items);
}
return this.Application.Get("Menu");
}
private DataTable PopulateRootLevel()
{
IDataReader objDataReader;
DataTable dt = new DataTable();
try
{
objDataUtility.CreateConnection(true);
objDataReader = objDataUtility.ExecuteDataReader(FrameWorkConstant s.FrameworkConstants.uspPopulateRootLevelMenu);
var values = new object[objDataReader.FieldCount];
for (int i = 0; i < objDataReader.FieldCount; i++)
{
dt.Columns.Add(objDataReader.GetName(i), objDataReader.GetFieldType(i));
dt.BeginLoadData();
}
while (objDataReader.Read())
{
objDataReader.GetValues(values);
dt.LoadDataRow(values, true);
}
dt.EndLoadData();
return dt;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
finally
{
objDataUtility.CloseConnection();
}
}
private void PopulateNodes(DataTable dt, MenuItemCollection items)
{
foreach (DataRow dr in dt.Rows)
{
MenuItem item = new MenuItem();
item.Text = dr["Title"].ToString();
item.Value = dr["Id"].ToString();
items.Add(item);
// Node with child nodes
bool flag = ((int)(dr["ChildNodeCount"]) > 0);
if (flag)
{
menuCreate(item);
}
}
}
private void PopulateSubLevel(int parentId, MenuItem parentMenu)
{
IDataReader objDataReader;
DataTable dt = new DataTable();
try
{
objDataUtility.CreateConnection(true);
objDataUtility.MakeInParam(FrameWorkConstants.Fram eworkConstants.ParameterParentId, DbType.Int32, 1, parentId);
objDataReader = objDataUtility.ExecuteDataReader(FrameWorkConstant s.FrameworkConstants.uspPopulateSubLevelMenu);
var values = new object[objDataReader.FieldCount];
for (int i = 0; i < objDataReader.FieldCount; i++)
{
dt.Columns.Add(objDataReader.GetName(i), objDataReader.GetFieldType(i));
dt.BeginLoadData();
}
while (objDataReader.Read())
{
objDataReader.GetValues(values);
dt.LoadDataRow(values, true);
}
dt.EndLoadData();
PopulateNodes(dt, parentMenu.ChildItems);
}
catch (Exception ex)
{
}
finally
{
objDataUtility.CloseConnection();
}
}
private void menuCreate(MenuItem menu)
{
MenuEventArgs e = new MenuEventArgs(menu);
PopulateSubLevel(Int32.Parse(e.Item.Value),e.Item) ;
}
Please have a look and let me know about it.
thanks a ton.
|

December 11th, 2009, 03:42 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
First my original code sample was completely arbitrary, it simply showed you the method of putting things into the cache and pullings back out of cache. That code sample [b]is[/b/] what you are looking for.
To reiterate: this line
Cache.Insert("Menu", <your data>, null, DateTime.Now.AddDays(1), TimeSpan.Zero);
is responsible for inserting things into cache. The first parameter is the name of the item you are putting into your cache the <your data> parameter is whatever data you want to store in cache. To pull things back out of cahce you simply refer to it by its name (the value you supplied for the first parameter above):
Menu.Data = Cache["Menu"];
Menu.Data here is a made up Class and property, I supply it only to demonstrate how to pull things out of cache. I am not going to critique your code since that is not what the question is about but I only see a few ways forward for you: you can either store the menu's Item collection in cahce once it has been populated or store and XML representation of your menu in cache and rebuild your menu from that. If it were me I would store and XML representation of the menu in cache.
Lastly I would like to point out that I am willing to help just about anyone but I have very little patience for people not willing to help themselves. Based on some of your comments it is apparent that you had not bothered to read the links I provided to the MSDN because, if you had, you would not of asked me the questions that you were asking. I am not here to code for you I am here to help you and put you on the right path to fixing your problem.
hth
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click  on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
|

December 14th, 2009, 11:54 AM
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Application context in asp.net web application
I tried using application context to get the menu data. But the 2nd time when data comes from application context, it looses its value by the time it comes out of the method. As a result full menu control is not visible.
The code written is:
objDataUtility.CreateConnection(false);
Object oMenu = Application.Get("Menu");
if (oMenu == null)
{
DataTable dt = PopulateRootLevel();
PopulateNodes(dt, mnuMenu.Items);
Application.Add("Menu", mnuMenu.Items);
}
oMenu = Application["Menu"];
sender = oMenu;
}
this code is not included in if(!Page.IsPostBack). though including it there also gives the same issue. :(
Any suggestion is highly appreciated.
Thanks
|

December 26th, 2009, 04:42 AM
|
Registered User
|
|
Join Date: Dec 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Application context
I am having a web application.The context of that application is defined in application.xml file as "cdms".Hence my URL is http://localhost:9080/cdms/.... ok.When my application if it works with another application called "trivoli" my context should change as "/trivoli/cdms".If it is not working with trivoli it should be like "cdms".How can i acheive it? Can any one find the answer.
Acnezine
|

December 26th, 2009, 05:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
a) How is this related to the original topic?
b) I don't understand what you're asking.
c) What's that sponsored link doing there? Is this post a joke?
Imar
|
|
 |