Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old December 11th, 2009, 11:39 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> 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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #12 (permalink)  
Old December 11th, 2009, 12:25 PM
Authorized User
 
Join Date: Dec 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
  #13 (permalink)  
Old December 11th, 2009, 03:42 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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."
===============================================
  #14 (permalink)  
Old December 14th, 2009, 11:54 AM
Authorized User
 
Join Date: Dec 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #15 (permalink)  
Old December 26th, 2009, 04:42 AM
Registered User
 
Join Date: Dec 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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
  #16 (permalink)  
Old December 26th, 2009, 05:32 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I map multiple context roots to a single web application? massterb J2EE 1 November 29th, 2009 01:47 AM
how to set context in web application [PLEASE HELP] arashdx J2EE 3 January 27th, 2009 03:53 AM
Application Context in C#.net dineshpdn Visual Studio 2005 0 October 10th, 2007 06:01 AM
A Chat Application using Context and Sessions kotaiah J2EE 0 October 10th, 2006 09:56 PM
How to create context help in web application? Alexds ASP.NET 2.0 Basics 1 February 1st, 2006 06:23 PM



All times are GMT -4. The time now is 09:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.