Question

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.

Was it helpful?

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...

OTHER TIPS

Have you tried this?

<form id="Form1" defaultfocus="Textbox1" runat="server"> 

Or since you mentioned a page in within a MasterPage so it will be in a ContentPlaceholder:

    ContentPlaceHolder cp = (ContentPlaceHolder) Master.FindControl("ContentPlaceHolder1");
    cp.FindControl("Textbox1").Focus();

Make sure you reference your Master in your aspx:

<%@ MasterType VirtualPath="~/MyMaster.master" %>

you can write the js code control the textbox in the client event window.onload=.....

if your page use the master page , you should find the the textbox firstly ,so then set the textbox focus. and you also should attention the events sequence of the page and master

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top