javascript - Lose the focus of the textboxes in gridview -


i have grid view in updatepanel :

<asp:updatepanel id="updatepanel3" runat="server">         <contenttemplate>             <asp:panel id="pnl_lect" runat="server">                 <asp:gridview id="gv_ques" runat="server" cssclass="formtable cr_center" autogeneratecolumns="false"                     showfooter="true" onrowdatabound="gv_ques_rowdatabound">                     <columns>                         <asp:templatefield headertext="عناصر التقييم">                             <itemtemplate>                                 <asp:label id="lbl_ques" runat="server" text='<%# bind("que_desc") %>'></asp:label>                              </itemtemplate>                             <footertemplate>                                 <asp:label id="label1" runat="server" text="الاجمالي"></asp:label>                             </footertemplate>                             <itemstyle width="45%" />                         </asp:templatefield>                         <asp:templatefield headertext="ممتاز (4)">                             <itemtemplate>                                 <telerik:radnumerictextbox id="txt_1" runat="server" dbvalue='<%# bind("grade_id1") %>'                                     autopostback="true" width="60px" minvalue="0" maxvalue="999999999" ontextchanged="txt_1_textchanged">                                     <numberformat groupseparator="" decimaldigits="0" />                                 </telerik:radnumerictextbox>                                 <asp:hiddenfield id="hf_1" runat="server" value="1" />                             </itemtemplate>                             <footertemplate>                                 <asp:label id="lbl_1" runat="server"></asp:label>                             </footertemplate>                         </asp:templatefield>                         <asp:templatefield headertext="جيد جدًا (3)">                             <itemtemplate>                                 <telerik:radnumerictextbox id="txt_2" runat="server" dbvalue='<%# bind("grade_id2") %>'                                     autopostback="true" width="60px" minvalue="0" maxvalue="999999999" ontextchanged="txt_1_textchanged">                                     <numberformat groupseparator="" decimaldigits="0" />                                 </telerik:radnumerictextbox>                                 <asp:hiddenfield id="hf_2" runat="server" value="2" />                             </itemtemplate>                             <footertemplate>                                 <asp:label id="lbl_2" runat="server"></asp:label>                             </footertemplate>                         </asp:templatefield>                         <asp:templatefield headertext="جيد (2)">                             <itemtemplate>                                 <telerik:radnumerictextbox id="txt_3" runat="server" dbvalue='<%# bind("grade_id3") %>'                                     autopostback="true" width="60px" minvalue="0" maxvalue="999999999" ontextchanged="txt_1_textchanged">                                     <numberformat groupseparator="" decimaldigits="0" />                                 </telerik:radnumerictextbox>                                 <asp:hiddenfield id="hf_3" runat="server" value="3" />                             </itemtemplate>                             <footertemplate>                                 <asp:label id="lbl_3" runat="server"></asp:label>                             </footertemplate>                         </asp:templatefield>                         <asp:templatefield headertext="مقبول (1)">                             <itemtemplate>                                 <telerik:radnumerictextbox id="txt_4" runat="server" dbvalue='<%# bind("grade_id4") %>'                                     autopostback="true" width="60px" minvalue="0" maxvalue="999999999" ontextchanged="txt_1_textchanged">                                     <numberformat groupseparator="" decimaldigits="0" />                                 </telerik:radnumerictextbox>                                 <asp:hiddenfield id="hf_4" runat="server" value="4" />                             </itemtemplate>                             <footertemplate>                                 <asp:label id="lbl_4" runat="server"></asp:label>                             </footertemplate>                         </asp:templatefield>                         <asp:templatefield headertext="ضعيف (0)">                             <itemtemplate>                                 <telerik:radnumerictextbox id="txt_5" runat="server" dbvalue='<%# bind("grade_id5") %>'                                     autopostback="true" width="60px" minvalue="0" maxvalue="999999999" ontextchanged="txt_1_textchanged">                                     <numberformat groupseparator="" decimaldigits="0" />                                 </telerik:radnumerictextbox>                                 <asp:hiddenfield id="hf_5" runat="server" value="5" />                             </itemtemplate>                             <footertemplate>                                 <asp:label id="lbl_5" runat="server"></asp:label>                             </footertemplate>                         </asp:templatefield>                     </columns>                 </asp:gridview>             </asp:panel>         </contenttemplate>     </asp:updatepanel> 

i lose focus every postback write following :

protected void txt_1_textchanged(object sender, eventargs e)         {             int progser = int.parse(session["prog_serial"].tostring());             int total = 0;             radnumerictextbox txt = (radnumerictextbox)sender;              gridviewrow r = (gridviewrow)txt.namingcontainer;              tablecell cell = null;              control parent = txt;             while ((parent = parent.parent) != null && cell == null)                 cell = parent tablecell;             int indexoftextboxcell = -1;             if (cell != null)                 indexoftextboxcell = r.cells.getcellindex(cell);               foreach (gridviewrow row in gv_ques.rows)             {                 if (row.rowtype == datacontrolrowtype.datarow)                 {                     total = total + int.parse(((radnumerictextbox)row.cells[indexoftextboxcell].controls[1]).value.tostring());                 }             }             ((label)gv_ques.footerrow.cells[indexoftextboxcell].controls[1]).text = total.tostring();              scriptmanager.registerstartupscript(this, this.gettype(), "selectandfocus", "$get('" + txt.clientid + "').focus();$get('" + txt.clientid + "').select();", true);//the focus         } 

now tab out of textbox, focus still doesn't quite set correctly. have tab once after postback work.how set focus tabbed 1 rather current textbox ?

one solution suggest use javascript dom storage. keep id of focus text input local storage:

$(':text').on("focus", function(){   localstorage.setitem("focusitem", this.id);//here set in localstorage id of textbox   //console.log(localstorage.getitem("focusitem"));test focus element id }); 

and on $(document).ready(function(){}); event can set focus on input textbox:

$('#' + localstorage.getitem("focusitem")).focus(); 

here live example. focus in text , after reload page.

keep in mind remove things in localstorage have explicitly clear them via localstorage.removeitem(itemname).

more specific info here. full screen live example.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -