[英]Textbox1.Focus(); does not work; as does not Page.SetFocus(Textbox1); why?
as stated both of these do not work (from Page_Load
): 如前所述,这两个都不起作用(来自
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.
form标签位于第二个母版页上,因此这就是为什么不在此处设置焦点的原因。
not working in: ie, firefox, chrome and safari (all latest versions). 无法使用:即Firefox,Chrome和Safari(所有最新版本)。
help! 救命! thnx
日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.
甚至谷歌都没有结果,并显示我这个问题。
ok, here is what the ACTUAL problem seems to be. 好的,这就是ACTUAL问题。
<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. 我不知道这些ID(ID =“ PlaceHolder1”)如何到达那里,但它们似乎是问题所在。
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. 我通过从头开始重新构建项目并查看focus方法是否在其中工作来解决问题,然后(除其他事项外,所以我可以在此处发布)我发现了这种差异。
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中:
ContentPlaceHolder cp = (ContentPlaceHolder) Master.FindControl("ContentPlaceHolder1");
cp.FindControl("Textbox1").Focus();
Make sure you reference your Master in your aspx: 确保您在aspx中引用了您的Master:
<%@ MasterType VirtualPath="~/MyMaster.master" %>
您可以在客户端事件窗口中编写用于控制文本框的js代码。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
您还应该注意页面和主页面的事件顺序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.