Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
312
Text box focus +WebAsyncRefreshPanel
posted

i have two textboxes one id and other for name and a listbox for displaying all the names and

5 image buttons add, save, edit , delete and cancel . if i click on add button id is automatically

generated and displayed in id textbox i need to get the focus of cursor to the name text box at the

same time. i give txtname.focus() function but it didnt work . I am using a WebAsyncRefreshPanel  in

the page . if i remove it i get the focus on the text box . but i need the refresh panel.pls give me a method

to get focus without removing the webasyunchronous refresh panel.Thanks in advance 

Parents
No Data
Reply
  • 24497
    Suggested Answer
    posted

    Hi,

    If I understood your question correctly, then you need to set focus to a particular control/element located in WARP after postback according to a particular action/control which triggered postback.

    I suggest to use clientEvents of WARP.
    On request you may check which element triggered postback and memorize (in global variable) id of element which should get focus after response.
    On response you may find reference to element which should get focus and call its focus/select member methods.

    Below sample will set focus to TextBox1 if Button1 was clicked, and set focus to TextBox2 if Button2 was clicked.

    <script type="text/javascript">
    var idForFocus = null;
    function WebAsyncRefreshPanel1_RefreshRequest(oPanel,oEvent,id)
    {
     idForFocus = null;
     if(!id)
      return;
     if(id.indexOf('Button1') >= 0)
      idForFocus = '<%=TextBox1.ClientID%>';
     if(id.indexOf('Button2') >= 0)
      idForFocus = '<%=TextBox2.ClientID%>';
    }

    function WebAsyncRefreshPanel1_RefreshComplete(oPanel)
    {
     if(!idForFocus)
      return;
     var txt = document.getElementById(idForFocus);
     if(txt) try
     {
      txt.select();
      txt.focus();
     }catch(ex){}
    }
    </script>
    <igmisc:WebAsyncRefreshPanel ID="WebAsyncRefreshPanel1" runat="server" RefreshComplete="WebAsyncRefreshPanel1_RefreshComplete"
     RefreshRequest="WebAsyncRefreshPanel1_RefreshRequest">
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
      <br />
      <asp:Button ID="Button1" runat="server" Text="Button1" />
      <asp:Button ID="Button2" runat="server" Text="Button2" />
    </igmisc:WebAsyncRefreshPanel>

Children