Archive

Archive for the ‘asp.net’ Category

ASP.NET: DefaultButton and DefaultFocus

June 13th, 2008 No comments

Since a while, on some of my company’s internet pages the DefaultButton and DefaultFocus properties did not work, although the code used seemed to be perfect. The problem was that the DefaultFocus javascript was not rendered at all.

After investigating the problem, I walked into two problems, solving which solved my problem as well:

1. DefaultButton requires a control’s UniqueID property, but DefaultFocus requires a control’s ClientID property. Strange, but it really works :) !
2. Do not use hyphen characters in your ID properties (I had an auto ID using a GUID), since it will cause your focus to fail (the javascript is not being rendered). If you have or want to use some kind of separation, use the underscore character instead (it will work).

Hope that helps somebody out there too ;) !

Technorati tags:

Set MasterPage (.master) title from a web form (.aspx)

February 22nd, 2008 No comments

Lots of people complain about not being able to change the master page’s title using ASP.NET 2.0 and up. A commonly seen tutorial is to use the following piece of code:

((HtmlTitle) Page.Master.FindControl("lblTitle")).Text =
    "Set some kind of title";

In most of the cases you need to change the master page’s title, you do not have to bother about this. Just use the correct page stadium and set the page’s title. The only page event to be able to do this is Page_PreInit (since master page and content page are still separate ‘pages’ in this stadium). The following will work (if you have AutoEventWireup enabled ;) ):

protected void Page_PreInit(object sender, EventArgs e)
{
    Title = "Set some kind of title";
}