06 June, 2008

ESRI & ASP.NET Master Pages

One of the great things about VS 2005 & ASP.NET 2.0+ is the ability to quickly and easily create and user Master Pages in your ASP.NET web application.

One of the horribly difficult things about Master Pages is when using mash-ups, figuring out how they work exactly. Ok, if you don't know about Master Pages, then you should probably investigate them some.

A Master Page is not really a page, but rather a template that holds containers into which pages render (but can also regular HTML there as well). So a Master Page can have your title, image banner, navigation links, login stuff, breadcrumb trail...all that stuff, and also contains one or more "ContentPlaceHolder" controls.

The problem when putting an ArcGIS Server map in a page that has a master page is that when the page is rendered, the name of the map changes. That is, if you leave you map the default "Map1" name, when rendered, it has the name "ct00_ContentPlaceHolder1_Map1". Assuming, of course, you lave the ContentPlaceHolder name the default AND you put the map in the first instance of the ContentPlaceHolder controls.

This creates issue when attempting to access the map via JavaScript. In the WebMapApp.js file that is defaultly created when a Web Mapping Application is created in VS2005, it is assuming that you leave everything as the default names when you put stuff in the map. With that in mind, it uses names like "Map1", "TaskResults1" etc.

To fix this, I created a global var in the javascript file:

var webMapControlPrefix = "ctl00_ContentPlaceHolder1_";



So, for instance, the setpageElementSizes() function goes to define the scale bar , it used to do:



webMapAppScaleBar = document.getElementById("ScaleBar1");



But now, I have it looking like this:



webMapAppScaleBar = document.getElementById(webMapControlPrefix+"ScaleBar1");



You probably get the idea. If not, drop a comment and I'll see what I can find out about whatever confusion there is.







3 comments:

Anonymous said...

Thanks for this post.

I have a question however. Is the following possible:
* Have a master page that contains the complete map and all needed controls and just basic navigation tools in the toolbar.
* Then have a couple of normal pages that uses this master page, and with the content placeholder add custom tools that are specific to each page.

Thanks :)

Unknown said...

I'm not certain, I've never tried it so can't really say one way or the other.

.net Obfuscator said...

I used the global variable but was not really able to call it during th time of execution is there anything else i need to do apart from calling it at the time of the execution.