在javascript中,是否将焦点放在表单视图中的控件上,在表中的InsertItemTemplate中?
我相信标题说明了一切。如何从javascript中获得表内InsertItemTemplate内FormView内控件的焦点 asp代码如下所示在javascript中,是否将焦点放在表单视图中的控件上,在表中的InsertItemTemplate中?,javascript,focus,getelementbyid,formview,edititemtemplate,Javascript,Focus,Getelementbyid,Formview,Edititemtemplate,我相信标题说明了一切。如何从javascript中获得表内InsertItemTemplate内FormView内控件的焦点 asp代码如下所示 <asp:Panel ...> <asp:UpdatePanel ...> <ContentTemplate> <asp:SqlDataSource ...> <asp:FormView ID=FormView1 ...> <InserItemTemp
<asp:Panel ...>
<asp:UpdatePanel ...>
<ContentTemplate>
<asp:SqlDataSource ...>
<asp:FormView ID=FormView1 ...>
<InserItemTemplate>
<asp:Table ID=tblIns ...>
<asp:TextBox ID=txtInsMyBox ....>
</asp:TextBox>
</asp:Table>
</InserItemTemplate>
<EditItemTemplate>
<asp:Table ID=tblUpd ...>
<asp:TextBox ID=txtUpdMyBox ....>
</asp:TextBox>
</asp:Table>
</EditItemTemplate>
</asp:FormView>
<asp:ValidationSummary />
<div>
<asp:Button ID="btnSave" .../>
<asp:Button ID="btnCancel" .../>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
标题中的javascript代码如下所示:
<script type="text/javascript">
function regainFocus() {
//this works
window.parent.document.getElementById("btnSave").focus();
//this also works
window.parent.document.getElementById("FormView1").focus();
//this does not work
window.parent.document.getElementById('<%#FormView1.FindControl("txtInsMyBox").ClientID%>').focus();
}
</script>
我尝试将标记从改为=符号,但没有任何区别。我还试图在FormView中找到其他不同的控件,但没有成功
有人能解释一下如何在FormView中查找表内对象的控件吗?页面上是否只有一个txtMyBox文本框?程序中有两个txtMyBox。一个用于更新,另一个用于插入。但是它们被命名为txtInsMyBox和txtpdmybox。在我的程序中,它们被命名为不同的名称:txtupddxxsooleeeooooooooooo。名称的长度有限制吗?我终于成功了,但不是通过在javascript中使用焦点。在我看来,javascript只能聚焦一个按钮,所以我放置了一个隐藏的按钮,名为btnSetFocus,它可以将焦点设置为formview中的对象。您可以将焦点设置为文本框。这不应该是个问题。