January 2009 - Posts

HowTo: Add a body onload script to a page that uses a MasterPage

When you use a MasterPage to define the design of your website, you might come across the problem that there is no body element in a web content form. This can be a problem when you want to add an onload script to a specific page. You could of course add the onload on the MasterPage, but you might not want the script to run on every page. There are several workarounds to fix this ‘problem’. The one I used last week was to do the following:

  1. Add the runat=”server” tag on the body in the MasterPage
  2. Add a unique ID on the body in the MasterPage
  3. Add a method to the MasterPage to set the onload for the body. This might look a bit like this (of course you can also have the script for the load be a parameter for the method):
       1: internal void SetBodyLoad()
       2: {
       3:     MasterPageBody.Attributes.Add("onLoad", "initialize()");
       4: }
  4. Add this line of code in the Page_Load of the page you want to have the onload:
       1: ((MasterPageName)Master).SetBodyLoad();

 

This worked for me! Hope this helps.

Posted by Rick van den Bosch | 1 comment(s)
Filed under: ,

(Re)surface

I know it has been a while since my last post, but I’m about to resurface! I’ve played in a musical the entire month of December and (because of that) we were busy getting our company up and running again in the new year. So now I’ll be developing more and I’ll probably have more things to blog about. So keep posted to see more stuff over here…

For now, here are some interesting articles about Microsoft’s Surface:

Posted by Rick van den Bosch | with no comments
Filed under: , ,