c# - How can I submit a Sharepoint page and retain its state (prevent it from re-initializing)? -
i have sharepoint web page starts off question user; once answer it, rest of page created. when user submits page via "save" button, page reverts initial (almost blank) state.
i'm trying work around - want page return former, pre-submit, glory.
i ran problems previously-created elements not wanting re-created due new instances having same ids previous instances (a "primary key violation" reckon).
so after posting situation here, thought had come solution when added code make each id unique, based on when instantiation takes place:
ckbximinsider.id = getyyyymmddhourminsecms() + "ckbxucscfacultystafforstudent"; // making ids unique, when same elements created multiple times (such before , after form submission) private string getyyyymmddhourminsecms() { datetime dt = datetime.now; string dateyyyymmdd = dt.tostring("yyyymmdd"); int hour = dt.hour; int min = dt.minute; int sec = dt.second; int millisec = dt.millisecond; string hourminsecmilliconcat = string.format("{0}{1}{2}{3}", hour, min, sec, millisec); return string.format("{0}{1}", dateyyyymmdd, hourminsecmilliconcat); }
with that, ids elements so:
so subsequent creation of elements following submission of page should generate new , different id, such "ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_2015072210842379boxemailsection1" or whatever instead of "ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_2015072210754251boxemailsection1"
it still doesn't work, though; dreaded "error unexpected error has occurred." rather cryptic correlation id. tracking down in log file, see entry of particular interest:
07/22/2015 09:51:38.33 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation runtime tkau unexpected system.web.httpexception: failed load viewstate. control tree viewstate being loaded must match control tree used save viewstate during previous request. example, when adding controls dynamically, controls added during post-back must match type , position of controls added during initial request. @ system.web.ui.control.loadviewstaterecursive(object savedstate) @ system.web.ui.control.addedcontrol(control control, int32 index) @ directpaymentsectionswebpart.dpsvisualwebpart.dpsvisualwebpartusercontrol.getsection1table(boolean cre8hiddenfield) @ directpaymentsectionswebpart.dpsvisualwebpart.dpsvisualwebpartusercontrol.generatesection1(boolean cre8hiddenfield) @ directpaymentsectionswebpart.dpsvisualwe... 2150ed41-3b86-42ac-93bf-72da4e68cec3
so tells me, "the control tree viewstate being loaded must match control tree used save viewstate during previous request..." why doesn't match, though, don't grok.
for full context, first appearance of correlation id (line 1240 in log file) last appearance of same (line 1254):
07/22/2015 09:51:37.50 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation logging correlation data xmnv medium name=request (post:https://financial.ucsc.edu:443/pages/finaff_demo_page_clay.aspx) 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.52 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly high leaving monitored scope (getfileandmetainfo). execution time=14.7337161566624 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.52 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly high leaving monitored scope (getwebpartpagecontent). execution time=14.945265389875 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.52 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation logging correlation data xmnv medium site=/ 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.52 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly high leaving monitored scope (postresolverequestcachehandler). execution time=19.2141040271878 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.65 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly high leaving monitored scope (ensurelistitemsdata). execution time=127.102117727253 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.66 w3wp.exe (0x1e08) 0x1fbc web content management content deployment 78fl unexpected sitecachesettings.isimportinprogress flag set true, import status has not been updated long time. 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.73 w3wp.exe (0x1e08) 0x1fbc web content management publishing 7fz3 medium setting [display] formcontext.formmode current page 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.73 w3wp.exe (0x1e08) 0x1fbc web content management publishing 7fz3 medium setting [display] formcontext.formmode current page 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.76 w3wp.exe (0x1e08) 0x1fbc document management server document management cm6w medium template discovery/initscriptdata: cannot user profile, no userprofileapplicationproxy exists in current context 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:37.76 w3wp.exe (0x1e08) 0x1fbc document management server document management cm6w medium template discovery/initscriptdata: cannot user profile, no userprofileapplicationproxy exists in current context 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:38.08 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly high leaving monitored scope (ensurelistitemsdata#1). execution time=277.14073995438 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:38.33 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation runtime tkau unexpected system.web.httpexception: failed load viewstate. control tree viewstate being loaded must match control tree used save viewstate during previous request. example, when adding controls dynamically, controls added during post-back must match type , position of controls added during initial request. @ system.web.ui.control.loadviewstaterecursive(object savedstate) @ system.web.ui.control.addedcontrol(control control, int32 index) @ directpaymentsectionswebpart.dpsvisualwebpart.dpsvisualwebpartusercontrol.getsection1table(boolean cre8hiddenfield) @ directpaymentsectionswebpart.dpsvisualwebpart.dpsvisualwebpartusercontrol.generatesection1(boolean cre8hiddenfield) @ directpaymentsectionswebpart.dpsvisualwe... 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:38.33 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation runtime tkau unexpected ...bpart.dpsvisualwebpartusercontrol.page_load(object sender, eventargs e) @ system.web.util.callihelper.eventargfunctioncaller(intptr fp, object o, object t, eventargs e) @ system.web.util.callieventhandlerdelegateproxy.callback(object sender, eventargs e) @ system.web.ui.control.onload(eventargs e) @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.control.loadrecursive() @ system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) 2150ed41-3b86-42ac-93bf-72da4e68cec3 07/22/2015 09:51:38.47 w3wp.exe (0x1e08) 0x1fbc sharepoint foundation monitoring b4ly medium leaving monitored scope (request (post:https://financial.ucsc.edu:443/pages/finaff_demo_page_clay.aspx)). execution time=968.813145246114 2150ed41-3b86-42ac-93bf-72da4e68cec3*
surely retaining last state of page prior submission common requirement , can't tough. think ability exposed through boolean, such "retainpriorstate" or such. or, since not literally possible, "restorepriorstate"
the way things should easy made difficult, hoop-jumping exercises in programming cause me ponder whether web invented , designed congressmen , other flavors of public criminals.
update
i'm trying re-create elements in page_load() event:
if (page.ispostback) {
...after trying set them visible there didn't work (because seen null); "catch-22": can't set elements (panels/divs) visible because null on postback, can't create them anew because...why? don't know....
update 2
visibleness apparently not state noted. when submit form/page, dynamically-created elements visible. however, on postback, none of dynamically-created elements visible.
i thought circumvent forcing toggling of radiobutton causes elements visiblized, in load_page() event, so:
if (ispostback) { rbpaymentforself.checked = false; rbpaymentforself.checked = true; }
the madness method radio button (rbpaymentforself) retains checkedness on postback, event (jquery*) fire, need first toggle off , on again.
here's jquery want fire via checking/unchecking of radio button:
$(document).on("click", '[id$=rbpaymentforself]', function () { if (this.checked) { $('[id$=panelsection2]').slideup(); $('[id$=panelsection3]').slideup();
show_sections(); $('[id$=rbpaymenttoindividual]').attr('checked', true).click(); $('[id$=boxemailsection1]').val(function () { return $('[id$=hfuseremail]').val(); }) }
});
function show_sections() { $('[id$=panelsection1]').slidedown(); $('[id$=panelsection4]').slidedown(); $('[id$=panelsection5]').slidedown(); $('[id$=panelsection5b]').slidedown(); $('[id$=btnsave]').slidedown(); }
my idea if code above worked, determine radiobutton toggle based on contents of session variable. but, poc did not work, it's coding board...
i try disabling viewstate now...
update 3
this.enableviewstate = false;
...changes nothing (strange (to me, anyway) true).
i found issue on msdn's blogs: why exception “failed load viewstate”
here's summary, in case link ever comes down:
cause
[f]or current post-back request, when try add controls dynamically, newly added control validated , see if matches control stored in previous viewstat. if not, above exception.
resolution
option 1:
you can disable viewstate of aspx page :
<%@ page language="c#" autoeventwireup="true" codebehind=" #####.aspx.cs" inherits="#####" enableviewstate="false"%>option 2:
you can change source code make sure controls added during post-back must match type , position of controls added during initial request.
fingers cross helps out.
Comments
Post a Comment