Wednesday, October 18, 2006

[ASP.NET] Specifying DefaultButton in MasterPage

In normal ASP.NET 2.0, we can easily assign the DefaultButton property in the

<form runat="server" DefaultButton="btnSearch">

But what if we would like to make two different buttons from two pages that inheriting the MasterPage to be DefaultButton? It might not be working using the way above because MasterPage because it is publicly shared by its content pages. You, however, have to programmatically assign the DefaultButton in each of the content page.

In content Page,

this.Form.DefaultButton = "MyDefaultButton";

This is not the way of assigning the ID of button to DefaultButton property. Use this way,

this.Form.DefaultButton = MyDefaultButton.UniqueID


1 comment:

info said...

I want to assign a default button when the user selects or clicks the textbox for search, otherwise the login button should be the default. I am particularly interested in the event which I should use when a user selects the search texbox.