0

我相信标题说明了一切。您如何从 javascript 的 Table 中的 InsertItemTemplate 中的 FormView 中获得焦点?

asp代码看起来像这样

<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 内的 Table 内查找对象的 FindControl 吗?

4

0 回答 0