Much frustration has arisen from the fact that changes made to the DOM in the initializeRequest method are not reflected on the server side. The problem is, the ViewState has already been wrapped up at this stage, and there is no other upstream method from initializeRequest.

There is a way around this problem, however. The answer is to simply cancel the postback, make your changes, and relaunch the postback. This causes the ViewState to be wrapped up after your new postback is initiated.  Here’s the code:

Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequest);

var bSecondPass = false;

function initializeRequest(sender, args){
if(!bSecondPass){
//
//make your changes to the DOM here
//
var prm = Sys.WebForms.PageRequestManager.getInstance();
bSecondPass = true;
prm.abortPostBack();
args.set_cancel(true);
__doPostBack(args.get_postBackElement().id, document.getElementById(“__EVENTARGUMENT”).value);
}else{
bSecondPass = false;
}
}

I’ll soon be writing an article on how this can be used to make the TinyMCE rich text editor play nice with ASP.Net Ajax UpdatePanels.  I’ve written a nice little TinyMCE Asp.Net Plugin that I’m going to package up and share with you guys.  Stay tuned!


Kick It on DotNetKicks.com