Today I want to fix a bug about viewvirtualdocument, and when clicking Cancel button it shoshould prompt a window about JavaScript but actually it can not work. So I debugging the program and find the problem is:
The page loads control on the page_load, and then excutes the codes of control, update the gridview, registes the Javascript into the button. at last excutes callback event. so problem happens, callback event does not deal with buttons, it only gets the data and response from server.
How to solve this problem?
I add a hiddenfield control into the subpagenavigationbar, every time when entering into the viewvirtualdocument page on the page_load, set the value like this:
_ Childrenchangedhidden = new hiddenfield ();
_ Browserspgw. Controls. Add (_ childrenchangedhidden );
Then registes JavaScript to cancel button on raisecallbackevent:
Bool ischanged = (this. virtualcontext. childrenmanager! = NULL & this. virtualcontext. childrenmanager. haschanged ());
_ Childrenchangedhidden. value = ischanged. tostring (). tolower ();
String script = string. Format ("Return avoidchildrenchangedconfirm ('{0}', '{1}');", _ childrenchangedhidden. clientid,
This. virtualcontext. virtualdocumentname. Replace ('\'',''));
_ Cancelbutton. Attributes. Add ("onclick", script );
And now it is in testing!