asp.net - Async/partial postback datagrid issues -
i'm trying aspx datagrid control perform post results in partial postback (asynchronous) rather full postback. i've added scriptmanager, update panel, , content template wrapper , yet still refreshes page when select data item , click add.
<asp:scriptmanager id="scriptmanager1" runat="server" enablepartialrendering="true" ></asp:scriptmanager> <asp:updatepanel id="uppnllookup" runat="server" updatemode="conditional" childrenastriggers="true"> <contenttemplate> <asp:datagrid id="objectpropertiesdatagrid" cellpadding="5" cellspacing="5" onitemcommand="objectpropertiesdatagrid_itemcommand" onitemdatabound="objectpropertiesdatagrid_itemdatabound" autogeneratecolumns="false" cssclass="list" datakeyfield="id" runat="server"> <asp:templatecolumn> <itemtemplate> <asp:panel id="multivaluepanel" visible="false" runat="server"> <table> <tr> <td valign="top"> <asp:button id="addbutton" cssclass="button" commandname="addvalue" width="65px" text="add" runat="server"></asp:button> <asp:button id="addallbutton" cssclass="button" commandname="addallvalue" width="85px" text="add all" runat="server"></asp:button> <br /> <asp:listbox id="listboxvalues" width="250px" cssclass="listbox" selectionmode="multiple" runat="server"></asp:listbox> </td> <td valign="top"> <asp:button id="removebutton" cssclass="button" text="remove" width="65px" commandname="removevalue" runat="server"></asp:button> <asp:button id="removeallbutton" cssclass="button" text="remove all" width="85px" commandname="removeallvalue" runat="server"></asp:button> <br /> <asp:listbox id="listboxcurrentvalues" width="250px" cssclass="listbox" selectionmode="multiple" runat="server"></asp:listbox> </td> </tr> </table> </asp:panel> </itemtemplate> </asp:templatecolumn> </asp:datagrid> </contenttemplate> <triggers> <asp:asyncpostbacktrigger controlid="addbutton" eventname="click" /> <asp:asyncpostbacktrigger controlid="removebutton" eventname="click" /> <asp:asyncpostbacktrigger controlid="addallbutton" eventname="click" /> <asp:asyncpostbacktrigger controlid="removeallbutton" eventname="click" /> </triggers> </asp:updatepanel> code behind (snippets/relevant methods):
protected void page_load(object sender, eventargs e) { savebutton.click += savebutton_click; btnaddchild.click += btnaddchild_click; btnaddchildtop.click += btnaddchildtop_click; deletebutton.click += deletebutton_click; cancelbutton.click += cancelbutton_click; copybutton.click += copybutton_click; newbutton.click += newbutton_click; addsitebutton.click += addsitebutton_click; removesitebutton.click += removesitebutton_click; activateall.click += activateall_click; deactivateall.click += deactivateall_click; startdatecalender.selectionchanged += startdatecalender_selectionchanged; enddatecalender.selectionchanged += enddatecalender_selectionchanged; startdatecalender.load += startdatecalender_load; enddatecalender.load += enddatecalender_load; cachebutton.click += cachebutton_click; if (ispostback) return; if (string.isnullorempty(request["id"])) { response.redirect("default.aspx"); } else { loaddata(); } } private void loaddata() { properties = contentproviderfactory.getcontentprovider().getobjecttypeproperties(currentcontentobject.type, false); uploadimage.datasource = datahelper.getobjectypeimagesizes(currentcontentobject.type); uploadimage.container = currentcontentobject; foreach (var property in property p in properties let objectproperty = currentcontentobject.getproperty(p.id) objectproperty == null select p) { currentcontentobject.items.add(property); } objectpropertiesdatagrid.datasource = properties; var children = contentproviderfactory.getcontentprovider().getcontentobjectchildren(currentcontentobject.id); dgobjectchildren.datasource = children.where(c => c.active); dgobjectinactivechildren.datasource = children.where(c => !c.active); dgobjectparents.datasource = contentproviderfactory.getcontentprovider().getcontentobjectparents(currentcontentobject); ddlcontenttypes.datasource = contentproviderfactory.getcontentprovider().getcontentobjecttypes(currentcontentobject.type); ddlcontenttypestop.datasource = contentproviderfactory.getcontentprovider().getcontentobjecttypes(currentcontentobject.type); siteslistbox.datasource = contentproviderfactory.getcontentprovider().getcontentobjectsitesavailable(currentcontentobject.id); setsiteslistbox.datasource = contentproviderfactory.getcontentprovider().getcontentobjectsites(currentcontentobject.id); if (currentcontentobject.id == 0) { response.status = "301 moved permanently"; response.addheader("location", "/admin/contentobjects/objectnotfound.aspx"); response.end(); } const string date_format = "mm/dd/yyyy"; if (currentcontentobject.startdate.tostring(date_format) != sqldatetime.minvalue.value.tostring(date_format)) { startdatetextbox.text = currentcontentobject.startdate.toshortdatestring(); } if (currentcontentobject.enddate.tostring(date_format) != sqldatetime.maxvalue.value.tostring(date_format)) { enddatetextbox.text = currentcontentobject.enddate.date.toshortdatestring(); } databind(); //if orphan child/child, remove 'add child' button , pulldown if (ddlcontenttypes.items.count == 0) { btnaddchild.visible = false; ddlcontenttypes.visible = false; } if (ddlcontenttypestop.items.count == 0) { ddlcontenttypestop.visible = false; btnaddchildtop.visible = false; } // add delete confirmation javascript deletebutton.attributes["onclick"] = "return confirm_object_delete();"; rendertypeheader(); renderbreadcrumb(); if (currentcontentobject.parentid == 0) { userinfo.addtohistory(currentcontentobject.id, currentcontentobject.name); } else { userinfo.addtohistory(currentcontentobject.parent.id, currentcontentobject.parent.name); } startcalenderpanel.visible = false; endcalenderpanel.visible = false; } protected void objectpropertiesdatagrid_itemcommand(object sender, datagridcommandeventargs e) { var id = (int)objectpropertiesdatagrid.datakeys[e.item.itemindex]; switch (e.commandname.tolower()) { case "clearimage": { // delete image (does not physically remove image replaced if new new 1 updates) var imageproperty = e.item.findcontrol("imageproperty") image; var tbfilename = e.item.findcontrol("tbfilename") textbox; tbfilename.text = string.empty; imageproperty.imageurl = string.empty; break; } case "addvalue": { // adds property value list of properites var listboxvalues = e.item.findcontrol("listboxvalues") listbox; var listboxcurrentvalues = e.item.findcontrol("listboxcurrentvalues") listbox; foreach(var item in listboxvalues.items.cast<listitem>().where(item => item.selected)) { // add item set values listboxcurrentvalues.items.add(item); } (var = listboxvalues.items.count - 1; >= 0; i--) { if (listboxcurrentvalues.items.findbyvalue(listboxvalues.items[i].value) != null) { listboxvalues.items.removeat(i); } } sortlistbox(listboxcurrentvalues); break; } case "removevalue": { var listboxvalues = e.item.findcontrol("listboxvalues") listbox; var listboxcurrentvalues = e.item.findcontrol("listboxcurrentvalues") listbox; for(var = listboxcurrentvalues.items.count - 1; >= 0; i--) { if(listboxcurrentvalues.items[i].selected) { listboxvalues.items.add(listboxcurrentvalues.items[i]); listboxcurrentvalues.items.removeat(i); } } sortlistbox(listboxvalues); break; } case "addallvalue": { var listboxvalues = e.item.findcontrol("listboxvalues") listbox; var listboxcurrentvalues = e.item.findcontrol("listboxcurrentvalues") listbox; foreach(listitem item in listboxvalues.items) { // add item set values listboxcurrentvalues.items.add(item); } for(var = listboxvalues.items.count - 1; >= 0; i--) { if(listboxcurrentvalues.items.findbyvalue(listboxvalues.items[i].value) != null) { listboxvalues.items.removeat(i); } } sortlistbox(listboxcurrentvalues); break; } case "removeallvalue": { var listboxvalues = e.item.findcontrol("listboxvalues") listbox; var listboxcurrentvalues = e.item.findcontrol("listboxcurrentvalues") listbox; (var = listboxcurrentvalues.items.count - 1; >= 0; i--) { listboxvalues.items.add(listboxcurrentvalues.items[i]); listboxcurrentvalues.items.removeat(i); } sortlistbox(listboxvalues); break; } case "addalldatalistvalue": { var datalistvalues = e.item.findcontrol("datalistvalues") datalist; var datalistcurrentvalues = e.item.findcontrol("currentdatalistvalues") datalist; foreach (datalistitem item in datalistvalues.items) { imagelink imagelink = imagelinks[id][item.itemindex]; currentimagelinks[id].add(imagelink); } (var = datalistvalues.items.count - 1; >= 0; i--) { if (currentimagelinks[id].contains(imagelinks[id][i])) { imagelinks[id].removeat(i); } } datalistvalues.datasource = imagelinks[id]; datalistcurrentvalues.datasource = currentimagelinks[id]; datalistvalues.databind(); datalistcurrentvalues.databind(); break; } case "removealldatalistvalue": { var datalistvalues = e.item.findcontrol("datalistvalues") datalist; var datalistcurrentvalues = e.item.findcontrol("currentdatalistvalues") datalist; (var = datalistcurrentvalues.items.count - 1; >= 0; i--) { imagelinks[id].add(currentimagelinks[id][i]); currentimagelinks[id].removeat(i); } datalistvalues.datasource = imagelinks[id]; datalistcurrentvalues.datasource = currentimagelinks[id]; datalistvalues.databind(); datalistcurrentvalues.databind(); break; } } }
i think have runtime error in page_load. example if have wrong codes, page refresh instead of update:
protected void page_load(object sender, eventargs e) { if (ispostback) { response.redirect("webform1.aspx"); int.parse(""); } }
Comments
Post a Comment