From: Argiris K. <be...@us...> - 2005-11-17 18:10:13
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18730/Core Modified Files: MagicAjaxModule.cs Log Message: Hacky stuff for 'Storing' page modes to provide the ViewState for a normal PostBack. Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MagicAjaxModule.cs 17 Nov 2005 15:03:16 -0000 1.10 --- MagicAjaxModule.cs 17 Nov 2005 18:10:01 -0000 1.11 *************** *** 543,548 **** if ( ! _isAjaxCall ) { ! // PostBack. Get the controls from stored page. ! requestPage.Init += new EventHandler(RequestedPage_Init); } else --- 543,555 ---- if ( ! _isAjaxCall ) { ! // PostBack. Do some really hacky stuff to get the real viewstate. ! ! string vs = GetViewStateOfPage(_currentPageInfo.Page); ! if (vs != null) ! { ! Util.SetPrivateField(_request.Form, typeof(NameObjectCollectionBase), "_readOnly", false); ! _request.Form["__VIEWSTATE"] = vs; ! Util.SetPrivateField(_request.Form, typeof(NameObjectCollectionBase), "_readOnly", true); ! } } else *************** *** 553,563 **** _response.Filter = _filter; ! if (_currentPageInfo.AjaxCallsCount == 0 ! && _currentPageInfo.Page.Validators.Count == 0) { ! // Restore the validators ! ArrayList validators = Util.GetChildControlsOfType(_currentPageInfo.Page, typeof(IValidator), false); ! foreach (IValidator valid in validators) ! _currentPageInfo.Page.Validators.Add (valid); } --- 560,575 ---- _response.Filter = _filter; ! if ( _currentPageInfo.AjaxCallsCount == 0 ) { ! // For bypassing the VerifyRenderingInServerForm check ! Util.SetPrivateField (_currentPageInfo.Page, typeof(Page), "_inOnFormRender", true); ! ! if ( _currentPageInfo.Page.Validators.Count == 0 ) ! { ! // Restore the validators ! ArrayList validators = Util.GetChildControlsOfType(_currentPageInfo.Page, typeof(IValidator), false); ! foreach (IValidator valid in validators) ! _currentPageInfo.Page.Validators.Add (valid); ! } } *************** *** 585,594 **** } - protected virtual void RequestedPage_Init(object sender, EventArgs e) - { - // TODO: Replace the controls of AjaxControls from requestedPage with controls from stored page. - return; - } - /// <summary> /// Handles the EndRequest event of the Application --- 597,600 ---- *************** *** 632,637 **** // Required for Page.Request/Page.Response to be valid Util.CallPrivateMethod (page, typeof(Page), "SetIntrinsics", _context); - // For bypassing the VerifyRenderingInServerForm check - Util.SetPrivateField (page, typeof(Page), "_inOnFormRender", true); ReadOnlyArrayList postDataChangedControls; --- 638,641 ---- *************** *** 806,809 **** --- 810,838 ---- ((IPostBackEventHandler)eventcontrol).RaisePostBackEvent(eventArgument); } + + /// <summary> + /// Hacky way to get the ViewState field value of a page. + /// </summary> + /// <param name="page"></param> + /// <returns></returns> + protected virtual string GetViewStateOfPage (Page page) + { + #if NET_2_0 + // TODO: Write the hacky way to get ViewState for NET 2.0 too. + return null; + #else + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(sb)); + + Util.SetPrivateField(page, typeof(Page), "_fOnFormRenderCalled", false); + Util.CallPrivateMethod(page, typeof(Page), "SavePageViewState"); + Util.CallPrivateMethod(page, typeof(Page), "OnFormRender", writer, String.Empty); + + string html = sb.ToString(); + int si = html.IndexOf("value=\"") + 7; + int ei = html.IndexOf('\"', si); + return html.Substring(si, ei - si); + #endif + } #endregion |