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:


var bSecondPass = false;

function initializeRequest(sender, args){
//make your changes to the DOM here
var prm = Sys.WebForms.PageRequestManager.getInstance();
bSecondPass = true;
__doPostBack(args.get_postBackElement().id, document.getElementById(“__EVENTARGUMENT”).value);
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