Thursday, November 1, 2007

Get Rid Of _ctl0 Prefix In UniqueID Of Master Page

Master Pages seemed to solve old problems pretty well but now we've got some new. If you wander how to get rid of the prefix _ctl0 that is the answer - just set an ID of the master page in Page_Init. For example if we have MyMaster.master file, we need to have similar to this code:

<script runat="server" type="text/C#">
protected void Page_Init( object sender, EventArgs e )
{
this.ID = "MyMaster";
}
</script>

NOTE: Do not use Load event! It causes problems with wizzard and multiview controls... more

2 comments:

Sun Hat Villas said...

Thanks, this helps a lot. I knew you had to name every control, but I wondered where that pesky _ctl0 control was. The master page itself, well, there you go :O)

Richard said...

You can change the value away from CT100 using:

protected void Page_Init(object sender, EventArgs e){ this.ID = "TheMasterPage"; }
In your code-behind, then at least you get a dedicated prefix.

eXTReMe Tracker