c# - Why isn't the UpdatePanel found to update the data -
i have following code in asp.net page:
<asp:updatepanel runat="server" clientidmode="static" updatemode="conditional" id="upclickshowtask"> <contenttemplate> <asp:linkbutton id="lbshowtask" cssclass="btnexport" clientidmode="static" runat="server" text="generate tasks" onclick="btnfilter_click"></asp:linkbutton> </contenttemplate> </asp:updatepanel> <asp:panel id="pagetab8" clientidmode="static" runat="server"> <asp:panel id="democli" clientidmode="static" runat="server" borderwidth="2" bordercolor="#ff0000"> <asp:updatepanel id="upgentaskcli" runat="server" updatemode="conditional" clientidmode="static"> <contenttemplate> client: <asp:label id="lblcli" clientidmode="static" runat="server" text=""></asp:label> <br /> onboarding date: <asp:label id="lblclidate" clientidmode="static" runat="server" text=""></asp:label> <br /> contact information: <asp:label id="lblclicont" clientidmode="static" runat="server" text=""></asp:label> <br /> notes: <asp:label id="lblclinotes" runat="server" clientidmode="static" text=""></asp:label> <br /> </contenttemplate> </asp:updatepanel> </asp:panel> </asp:panel>
the code-behind:
protected void btnfilter_click(object sender, eventargs e) { democli.visible = false; demosit.visible = false; demopra.visible = false; demopro.visible = false; connstring = @""; //my connection string #region queries string querycli = @"select c.objectid ,c.attr2815 'client' ,c.attr2881 'onboarding date' ,c.attr2880 'contact information' ,m.memo 'notes' hsi.rmobjectinstance1231 c inner join hsi.rmmemo m on c.mk2879 = m.memoid"; string querysit = @"select s.objectid ,s.attr2819 'site' ,s.fk2820 'relatedclient' ,s.attr2873 'address' ,s.attr2874 'city' ,s.attr2875 'state' ,s.attr2876 'zip' ,m.memo 'notes' ,s.attr2878 'onboarding date' hsi.rmobjectinstance1229 s inner join hsi.rmmemo m on s.mk2877 = m.memoid"; string querypra = @"select p.objectid ,p.attr2817 'practice' ,p.fk2818 'relatedsite' ,p.attr2882 'onboarding date' ,m.memo 'notes' hsi.rmobjectinstance1230 p inner join hsi.rmmemo m on p.fk2818 = m.memoid"; string querypro = @"select p.objectid ,p.attr2919 'provider' ,p.attr2920 'start date' ,p.fk2921 'relatedpractice' ,p.fk2922 'relatedclient' hsi.rmobjectinstance1249 p"; #endregion string query = ""; using (sqlconnection conn = new sqlconnection(connstring)) { if (ddlcli.selectedindex > 0) { try { democli.visible = true; query = querycli + " c.attr2815 = '" + ddlcli.selectedvalue + "'"; // create data adapter sqldataadapter da = new sqldataadapter(query, conn); // query database , return result datatable dataset mydataset = new dataset(); da.fill(mydataset); lblcli.text = mydataset.tables[0].rows[0]["client"].tostring(); lblclidate.text = mydataset.tables[0].rows[0]["onboarding date"].tostring(); lblclicont.text = mydataset.tables[0].rows[0]["contact information"].tostring(); lblclinotes.text = mydataset.tables[0].rows[0]["notes"].tostring(); } catch (exception ex) { string error = ex.message; } } if (ddlsit.selectedindex > 0) { try { demosit.visible = true; query = querysit + " s.attr2819 = '" + ddlsit.selectedvalue + "'"; // create data adapter sqldataadapter da = new sqldataadapter(query, conn); // query database , return result datatable dataset mydataset = new dataset(); da.fill(mydataset); lblsit.text = mydataset.tables[0].rows[0]["site"].tostring(); lblsitrc.text = mydataset.tables[0].rows[0]["relatedclient"].tostring(); lblsitadd.text = mydataset.tables[0].rows[0]["address"].tostring(); lblsitcity.text = mydataset.tables[0].rows[0]["city"].tostring(); lblsitst.text = mydataset.tables[0].rows[0]["state"].tostring(); lblsitzip.text = mydataset.tables[0].rows[0]["zip"].tostring(); lblsitondate.text = mydataset.tables[0].rows[0]["onboarding date"].tostring(); lblsitnotes.text = mydataset.tables[0].rows[0]["notes"].tostring(); //upgentaskcli.update(); } catch (exception ex) { string error = ex.message; } } if (ddlpra.selectedindex > 0) { try { demopra.visible = true; query = querypra + " p.attr2817 = '" + ddlpra.selectedvalue + "'"; // create data adapter sqldataadapter da = new sqldataadapter(query, conn); // query database , return result datatable dataset mydataset = new dataset(); da.fill(mydataset); lblpra.text = mydataset.tables[0].rows[0]["client"].tostring(); lblprars.text = mydataset.tables[0].rows[0]["relatedsite"].tostring(); lblpraondate.text = mydataset.tables[0].rows[0]["onboarding date"].tostring(); lblpranotes.text = mydataset.tables[0].rows[0]["notes"].tostring(); } catch (exception ex) { string error = ex.message; } } if (ddlpro.selectedindex > 0) { try { demopro.visible = true; query = querypro + " p.attr2919 = '" + ddlpro.selectedvalue + "'"; // create data adapter sqldataadapter da = new sqldataadapter(query, conn); // query database , return result datatable dataset mydataset = new dataset(); da.fill(mydataset); lblpro.text = mydataset.tables[0].rows[0]["provider"].tostring(); lblprostart.text = mydataset.tables[0].rows[0]["start date"].tostring(); lblprorp.text = mydataset.tables[0].rows[0]["relatedpractice"].tostring(); lblprorc.text = mydataset.tables[0].rows[0]["relatedclient"].tostring(); } catch (exception ex) { string error = ex.message; } } upgentaskcli.update(); } }
i added breakpoints these lines:
lblcli.text = mydataset.tables[0].rows[0]["client"].tostring(); lblclidate.text = mydataset.tables[0].rows[0]["onboarding date"].tostring(); lblclicont.text = mydataset.tables[0].rows[0]["contact information"].tostring(); lblclinotes.text = mydataset.tables[0].rows[0]["notes"].tostring();
and hovering mouse on them, displays text data upgentaskcli
not updating show data.
i receive error:
0x800a139e - microsoft jscript runtime error: sys.invalidoperationexception: not find updatepanel id 'upgentaskcli'. if being updated dynamically must inside updatepanel.
how resolve issue?
since js visibilty error, try put update panel inside update panel this:
//this how view should like
<asp:updatepanel id="pnlparent" runat="server" updatemode="conditional"> <contenttemplate> <asp:updatepanel id="upgentaskcli" runat="server" updatemode="conditional" clientidmode="static"> <contenttemplate> client: <asp:label id="lblcli" clientidmode="static" runat="server" text=""></asp:label> <br /> onboarding date: <asp:label id="lblclidate" clientidmode="static" runat="server" text=""></asp:label> <br /> contact information: <asp:label id="lblclicont" clientidmode="static" runat="server" text=""></asp:label> <br /> notes: <asp:label id="lblclinotes" runat="server" clientidmode="static" text=""></asp:label> <br /> </contenttemplate> </asp:updatepanel> </contenttemplate> </updatepanel>
so in code behind following :
protected void page_load(object sender, eventargs e) { if (!ispostback) { scriptmanager.registerstartupscript (this, typeof(page), "updatemsg", "$(document).ready(function(){$('#upgentaskcli').hide();});", true); } }
//and in button logic add following line in if clause :
protected void btnfilter_click(object sender, eventargs e) { if (ddlcli.selectedindex > 0) { try { query = querycli + " c.attr2815 = '" + ddlcli.selectedvalue + "'"; // create data adapter sqldataadapter da = new sqldataadapter(query, conn); // query database , return result datatable dataset mydataset = new dataset(); da.fill(mydataset); lblcli.text = mydataset.tables[0].rows[0]["client"].tostring(); lblclidate.text = mydataset.tables[0].rows[0]["onboarding date"].tostring(); lblclicont.text = mydataset.tables[0].rows[0]["contact information"].tostring(); lblclinotes.text = mydataset.tables[0].rows[0]["notes"].tostring(); } catch (exception ex) { string error = ex.message; } scriptmanager.registerclientscriptblock (this, typeof(system.web.ui.page), "myjsfunction", "$('#upgentaskcli').toggle();", true); }
//it should work
Comments
Post a Comment