In javascript get focus on control inside FormView within InsertItemTemplate within Table?

256 views Asked by At

I believe the title says it all. How do you get focus on a control inside FormView within InsertItemTemplate within a Table from javascript?

The asp code looks like this

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

And the javascript code which is in the header looks like this:

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

I have tried changing the tag from "#" to "=" sign and it made not difference. I have also tried to find other different controls inside the FormView with no success.

Can somebody shed some light on how to FindControl of an object inside a Table inside a FormView?

0

There are 0 answers