Set the DefaultFocus or DefaultButton in a Page Based on a Master Page

When user type in the keyword in the search textbox and press the Enter key on keyboard, the webpage just do a simple postback. It doesn’t run the query until the user hit the “Search” button.

Use defaultfocus and defaultbutton.
defaultfocus puts the mouse cursor into the control when the page loads
defaultbutton cause the button click event, without it, it just cause a pagepost back

Because of the Master page, UniqueID and ClientID is necessary for this to work properly.

protected void Page_Load(object sender, EventArgs e)
Page.Form.DefaultButton = this.Button_Continue.UniqueID;
Page.Form.DefaultFocus = this.TextBox_PN.ClientID;


No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: