Search code examples
c#asp.netfocussetfocus

Textbox1.Focus(); does not work; as does not Page.SetFocus(Textbox1); why?


as stated both of these do not work (from Page_Load):

Textbox1.Focus();

or

Page.SetFocus(Textbox1);

any idea why?

this is the control itself:

<asp:TextBox ID="Textbox1" ClientIDMode="Static" CssClass="Textbox1"
                runat="server" MaxLength="80"></asp:TextBox>

it is located on a page, two master pages deep. the form tag is on the second master page, so that is why the focus is not being set there.

not working in: ie, firefox, chrome and safari (all latest versions).

help! thnx

edit: need any more info? i'll do / post anything just tell me what to do to help you help me, i tried EVERYTHING. even google is out of results and is showing my this question.


Solution

  • ok, here is what the ACTUAL problem seems to be.

    <asp:Content ID="PlaceHolder1" ContentPlaceHolderID="PlaceHolder1"
        runat="server">
    

    i have no idea how those ID's (ID="PlaceHolder1") got there, but they seem to be the problem.

    i figured it out by remaking the project from scratch and seeing if the focus method works in there, then (among other things, so I could post here) i found out this difference.

    this works:

    <asp:Content ContentPlaceHolderID="PlaceHolder1" runat="server">
    

    hope this helps someone, sometime...