Brendan Enrick

Daily Software Development

Visual Studio 2008 JavaScript Intellisense!

For those of you who do not read Scott Guthrie’s Blog, you really should. I know that any time I need to write JavaScript I switch out of Visual Studio, but I will not have to with Visual Studio 2008. It is supposed to have much better support for JavaScript development. Even Intellisense. For anyone interested you should check out this recent blog entry from Scott Guthrie which gives a lot of cool information about Visual Studio 2008’s JavaScript Intellisense.

I can’t wait to start using VS 2008. It has a lot of great features I plan on getting a lot of use out of.

Accessing Master Page Properties from a content page

As I mentioned in my previous blog post about Accessing a property of a base page from a user control, I am going to explain how to access a property on a MasterPage from the content page. One merely has to check the namespace and the class name of the masterpage, which can be found in the code behind file. Just cast the Content Page’s Master as the class of the masterpage file which it uses, and then just access the value. It is really quite simple.

int neededValue = ((MyNameSpace.MyMasterPageClassName)Master).MyProperty;

Using that method you are able to easily access a property of a masterpage file when needed.

Accessing Properties of a Base Page from a User Control

Earlier today I was helping someone who was working with a user control. That control was on an ASP.NET page which was inheriting from a base page. From the user control he could not access the properties of the base page. He mentioned that he was getting an error message which said that the property did not exist in the current context.

I showed him that the reason he was having the problem is because the code in the user control came from the page before, and thus he would need to get the properties from there, but he was also going to need to cast the Page as the base Page in order to get to the property.

int myImportantValue = ((MyBasePage)Page).ImportantProperty;

This will retrieve the value from the property of the base page. It is a fairly simple task. Perhaps next I will show how to do a similar task with a masterpage.

I've now added that blog post about Accessing a Property of a MasterPage from a Content Page

Clearing Page Output Cache Entries

Earlier today I had a situation where I needed to clear the output cache entry of a page. After a quick Google search I turned up Steve Smith’s Article on Removing Page Output Cache Entries.

The article is a short, helpful article which quickly and easily explains how to remove the output cache entry of a page.

private void RemoveButton_Click(object sender, System.EventArgs e)
{
    HttpResponse.RemoveOutputCacheItem("/caching/CacheForever.aspx");
}

I hope everyone else finds this to be easy to understand and implement. The above should work as long as you have a page named “CacheForever.aspx” in the folder “caching” at the root of the site.

Happy Caching!