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 hel开发者_如何转开发p me, i tried EVERYTHING. even google is out of results and is showing my this question.
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...
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
精彩评论