c# - Why is this code executed but ignored? -
in sharepoint page, on form submission, elements revert original state (if checkbox unchecked begin, checked user, reverts unchecked, etc.).
fair enough.
but want "save state" , return sorts of things way were. 1 thing in particular visibility of dropdownlist. if visible when "save" button selected, should return being visible after form submitted; 2 dropdownlists, of @ 1 visible @ given time, start off invisible or, more specifically, "slid up" so:
$(window).load(function () { $('[id$=ddlpaytoindividual]').hide(); $('[id$=ddlpaytovendor]').hide(); });
in trying save visible state of dropdownlists, i've added bools:
bool paymenttoanindividualdropdownchosen = false; bool paymenttoavendordropdownchosen = false;
...and assign them when save button selected:
private void btnsave_click(object sender, eventargs e) { try { // note current state of elements, can restored after saving/submitting paymenttoanindividualdropdownchosen = rbpaymenttoindividual.checked; paymenttoavendordropdownchosen = rbpaymenttovendor.checked; . . . }
i try set them @ end of same handler (the save button's click event) so:
if (paymenttoanindividualdropdownchosen) { //rbpaymenttoindividual.checked = true; <= didn't work - jquery not respond programatic clicks! ddlpaymenttoindividual.visible = true; }
the code reached, , visible value set true (provided had made dropdown visible checking "rbpaymenttoindividual" prior selecting save button, has no effect - dropdown remains hidden.
as can deduce commented-out code, tried programatically checking radiobutton which, when done manually, sets off following client-side code:
$(document).on("click", '[id$=rbpaymenttoindividual]', function () { if (this.checked) { $('[id$=ddlpaytovendor]').slideup(); $('[id$=ddlpaytoindividual]').slidedown(); } });
...but apparently jquery not respond programatically-induced events.
or timing issue? because form still in "submit" phase/state not working -- either client-side or server-side code, or both?
if problem - submit doesn't finish until after save button handler exits, , i'm setting dropdown visible - can put code accomplish setting of form state before submit? page_load() event place and, if so, there property can interrogate determine if form has been submitted?
update
i moved code end of page_load() event, so:
if (page.ispostback) { if (paymenttoanindividualdropdownchosen) { ddlpaymenttoindividual.visible = true; } }
...but, because whole shebang starts fresh, paymenttoanindividualdropdownchosen's initialized value of false seen, , intentions, though good, keeping company brimstone.
so how can revert pre-submit state - .ini file, or registry usage, or cookie, usual way accomplish this?
update 2
what seems odd am able revert pre-submit state of htmltable; code in save button click handler:
// re-visiblize rows vals if (rowcontainsvals(3)) { foapalrow3.style["display"] = "table-row"; } if (rowcontainsvals(4)) { foapalrow4.style["display"] = "table-row"; } if (rowcontainsvals(5)) { foapalrow5.style["display"] = "table-row"; } if (rowcontainsvals(6)) { foapalrow6.style["display"] = "table-row"; }
...and works fine (any rows vals displayed, although @ beginning, 1 row displays). stranger yet, perhaps, function:
private bool rowcontainsvals(int rownum) { bool rowdirty = false; switch (rownum) { case 3: rowdirty = ((!string.isnullorempty(boxfund2.text)) || (!string.isnullorempty(boxindex2.text)) || (!string.isnullorempty(boxorganization2.text)) || (!string.isnullorempty(boxaccount2.text)) || (!string.isnullorempty(boxactivity2.text)) || (!string.isnullorempty(boxamount2.text))); break; case 4: rowdirty = ((!string.isnullorempty(boxfund3.text)) || . . .
...finds values in input text boxes; if state of dropdownlist being visible lost during submit, why not values in textboxes/text input lost?
something rotten in redmond (or somewhere).
update 3
in response , here more code relative 2 dropdowns in question:
code-behind / c#:
rbpaymenttoindividual = new radiobutton { cssclass = "finaff-webform-field-input", id = "rbpaymenttoindividual" }; rbpaymenttoindividual.text = payment_or_reimbursement_to_an_individual; rbpaymenttoindividual.groupname = "paymentto"; rbpaymenttoindividual.checked = false; cellradiobutton1_1.controls.add(rbpaymenttoindividual); rbpaymenttovendor = new radiobutton { cssclass = "finaff-webform-field-input", id = "rbpaymenttovendor" }; rbpaymenttovendor.text = payment_to_a_vendor; rbpaymenttovendor.groupname = "paymentto"; cellradiobutton2_1.controls.add(rbpaymenttovendor);
rendered htm "view source":
<input id="ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_rbpaymenttoindividual" type="radio" name="ctl00$ctl24$g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33$ctl00$paymentto" value="rbpaymenttoindividual" /> <input id="ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_rbpaymenttovendor" type="radio" name="ctl00$ctl24$g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33$ctl00$paymentto" value="rbpaymenttovendor" />
Comments
Post a Comment