Posted by : Alon Havivi Thursday, September 24, 2009

To sets the browser focus to a specified control and/or set a Default button in your web part, You can use this code:

protected override void CreateChildControls()
{
TextBox txtTextBox = new TextBox();
txtTextBox.ID = "txtMyTextBox";

//Make sure you first add the control then set fucus

this.Controls.Add(txtTextBox);

this.Page.SetFocus(txtTextBox.ClientID);

Button btnSave = new Button();

btnSave.ID = "mySaveButton";
btnSave.Text = "Save";

//Make sure you first add the control then set the default
button

this.Controls.Add(btnSave);

this.Page.Form.DefaultButton = btnSave.UniqueID;

}

Popular Post

- Copyright © Alon Havivi's Blog -