Tuesday, May 02, 2006

How to use DefaultFocus and DefaultButton properties with Master page

Want to set default button (submit) and default input control in ASP.NET 2.0?
No problem - use Page.Form.DefaultFocus and Page.Form.DefaultButton properties.

But what if you work with Master Page or trying to implement User Control (Server Control)?

Short answer:
Page.Form.DefaultFocus = TextBox1.UniqueID;
Page.Form.DefaultButton = Button1.UniqueID;

Longer answer is here:
How do I set DefaultFocus or DefaultButton

Keywords: ASP.NET 2.0, C# 2.0, MSDN2


Anonymous said...

Do you mean?:

Short answer:
Page.Form.DefaultFocus = TextBox1.ClientID;
Page.Form.DefaultButton = Button1.UniqueID;

There seems to be a discrepancy between the short answer and the long answer in terms of which property of the text box is assigned to the forms DefaultFocus property.

Dennis Gorelik said...


I think you are right.
But I didn't use master pages for a while (I think it doesn't worth to).


About Me

My photo
Email me: blog@postjobfree.com