Mental Jetsam

By Peter Finch

Archive for April, 2007

Using a Microsoft Atlas UpdatePanel on Master Pages with multiple ContentPlaceHolders

Posted by pcfinch on April 4, 2007

ASP.NET Atlas Master Page StructureThis scenario is pretty straight forward. You have a MasterPage with 2 ContentPlaceHolders, one for the menu on the left and one for the content on the right (A simple label in this case). When you select a menu item on the left you want to update the content page on the right using AJAX.

Normally, all you have to do to accomplish this is to add an Atlas UpdatePanel.

1. Add the ScriptManager to the MasterPage.

<asp:scriptmanager id="scriptmanager1" runat="server"></asp:scriptmanager>

2. Add the UpdatePanel to the corresponding Content section of the Content page

3. Add the controls to the UpdatePanel that you want to update using AJAX.

4. Add a Trigger to the UpdatePanal that references the control (e.g. Menu1) and the event (e.g. MenuItemClick). This can be done manually in the HTML source view or from the Triggers field, in the Behavior properties section.

<asp:AsyncPostBackTrigger ControlID="Menu1" EventName="MenuItemClick"></asp:AsyncPostBackTrigger>

Normally, with Atlas, this is all you have to do, however, when using Master Pages you will get an error on the page something like this.

A control with ID 'Menu1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.]

The reason for this message is that Controls in Content pages of Master pages do not actually have their original ID’s. For example, although Menu1’s ID is “Menu1” it’s actual UniqueID is something like “ctl00$Menu$Menu1”. The real problem is that you do not know this until runtime. You could add a AsyncPostBackTrigger() manually to the UpdatePanel.Triggers collection at runtime in the OnInit() function using static strings, but this is not very maintainable.

The following method simply looks through the triggers on the UpdatePanel and for the one that ends with the ID of the Menu1 control it simply changes the trigger ControlID to the UniqueID of Menu1 as runtime. This MUST happen in the OnInit() method of the Content Page. Although you have to hardcode the Menu1 item (and any other trigger controls), it means that you can change the Menu’s ID or even the EventName without having to touch the code.

protected override void OnInit(EventArgs e)
   foreach (AsyncPostBackTrigger apbt in UpdatePanel1.Triggers) {
      if (Menu1.UniqueID.EndsWith(apbt.ControlID))
         apbt.ControlID = Menu1.UniqueID;

Posted in C#.NET | 10 Comments »

Centering fixed width HTML Content on a page

Posted by pcfinch on April 2, 2007

Centering fixed width HTML content (like this page) on a page sounds simple, but it’s hard to make it multi-browser compatible. The best way I have found, to date, is to center the BODY text using “text-align : center;” and then have a DIV inside it (containing the content) that uses “margin-left : auto; margin-right : auto; width : 720px ; text-align : left ;“. I have tested this on IE6, FireFox 2, Opera 8.5 and Netscape 8 and it seems to work fine.

There does appear to be a little problem with FireFox, however, as the minimum width of the containing page seems to be controlled by some external source (something other that the actual page) and “min-width:640px;” does not appear to have any effect. My guess us that the minimum toolbar width might have something to do with it. This has the effect that you can only reduce the page width to a curtain size and then is stops.

<title>Center Page Content Example</title>
<style type="text/css">
body {
margin : 0px ;
border : 1px blue solid ;
padding-top: 0px ;
margin-top : 0px ;
text-align : center;
background-color : #f0f0f0 ;
#page {
border : 1px blue solid ;
margin-left : auto;
margin-right : auto;
width : 720px ;
text-align : left ;
background-color : #d0d0d0 ;
#menu {
white-space: nowrap ;
width : 80px ;
vertical-align : top ;
background-color : white ;
vertical-align : top ;
<div id="page">
<table width="100%" border="1">
<tr><td colspan='2'><h1>Center Page Content Example</h1></td></tr>
<td id="menu">Menu 1<br>Menu 2<br>Menu 3</td>
<td id="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer,
varius eu, rhoncus a,venenatis at, libero. Fusce ullamcorper orci.
Sed velit metus, mattis nec, suscipit quis, porta nec, tellus. Etiam
nulla, interdum a, eleifend non, vulputate sed, purus. Donec. Nulla
consequat, leo eget porta accumsan, justo libero vestibulum
dictum leo lectus eget lacus. Vestibulum varius, orci id tristique
arcu enim blandit elit, id dignissim odio ipsum id dolor. Sed pulvinar
arcu. Sed gravida eleifend elit. Pellentesque sit amet dui. Sed
eros. Sed lacinia velit elementum dui. Morbi bibendum quam

Posted in CSS, HTML | Leave a Comment »

Basic network information using VBScript

Posted by pcfinch on April 1, 2007

The following VBScript runs on MS/Windows and displays the current network information available from the WScript.Network object. The code produces a simple messagebox to display the information. A good reference for this information can be found at

Set WshNetwork = WScript.CreateObject("WScript.Network")
CR = chr(13)
' Get printers
Set Printers = WshNetwork.EnumPrinterConnections
strPrinters = ""
For i = 0 to Printers.Count - 1 Step 2
strPrinters = strPrinters& "  " & Printers.Item(i) & "(" & Printers.Item(i+1) & ")" & CR

' Get drives
Set Drives = WshNetwork.EnumNetworkDrives
strDrives = ""
For i = 0 to Drives.Count - 1 Step 2
strDrives = strDrives & "  " & Drives.Item(i) & "(" & Drives.Item(i+1) & ")" & CR

MsgBox "WshNetwork.ComputerName = " & WshNetwork.ComputerName & CR &_
"WshNetwork.UserDomain = " & WshNetwork.UserDomain & CR &_
"WshNetwork.UserName = " & WshNetwork.UserName & CR &_
"WshNetwork.AddPrinterConnection (Method) "& CR &_
"WahNetwork.AddWindowsPrinterConnection (Method) " & CR &_
"WshNetwork.EnumPrinterConnections (Method) " & CR &_
strPrinters &_
"WshNetwork.RemovePrinterConnection (Method) " & CR &_
"WshNetwork.SetDefaultPrinter (Method) " & CR &_
"WshNetwork.EnumNetworkDrives (Method) " & CR &_
strDrives &_
"WshNetwork.MapNetworkDrive (Method) " & CR &_
"WshNetwork.RemoveNetworkDrive (Method) "

Posted in VBScript | Leave a Comment »