Set the default focus of an aspx page onto a button

26 Views Asked by At

Hi I have a button as in the below pic in my aspx page in Web-farm,

<div style="padding-top:20px; padding-left:10px;"><Web:MyCalSTRSButton ID="ProceedButton" runat="server" Text="Proceed to next step" OnClick="ProceedButton_Click" CssClass="disableButtonOnClick" />&nbsp;&nbsp;&nbsp;<Web:MyCalSTRSButton ID="CancelButton" runat="server" Text="Cancel" OnClick="CancelButton_Click" /></div>

Default focus of the Page is set to a Textbox in the Page, how can I set the focus on the above button, I have tried in the below ways.

 protected override void Page_Init(object pSender, System.EventArgs pArgs)
 {
     base.Page_Init(pSender, pArgs);     
     Page.SetFocus(ProceedButton);
 }


protected override void Page_Load(object pSender, System.EventArgs pArgs)
    {
        base.Page_Load(pSender, pArgs);
        

        if (!this.IsPostBack)
        {
           ///some code here
        }
        this.ProceedButton.Focus();           
    }

Any help to set the focus please?

0

There are 0 best solutions below