Hi all,
I have found what could be a possible bug in the beta 1 regarding the use of the UpdatePanel with postback events.
If we use the update panel and inside it there is a control like a linkbutton that raise a postback, then the event is generated on the server and everything is going on correctly.
In my scenario I have a base page class that overrides the Viewstate load and save methods to compress and decompress it.A simply code that work fine without ajax and with the atlas ctp.(the code put the compressed viewstate content in another hidden field and let the original __VIEWSTATE empty).
With beta1 I've found that with a viewstate compression, this cause the postback events not raised with the right postback value.This happens for example when we click for the second time to the link button, when the viewstate has to be regenerated from the previous click.
I don't know what happens but I think that something has changed in the way the beta1 and UpdatePanel look at the viewstate.
Anyone has had the same issue ?
I just had this problem occur to me this afternoon. Upgraded to the new beta 2 from Atlas and the controls inside my update panels that stored values in ViewState started behaving funny. I too was inheriting from a base class that compressed and cached ViewState. As soon as I took this out and went back to System.Web.UI.Page, the controls worked fine again. This really sucks as we were able to trim so much bloat out of the page by compressing the ViewState. It would be wonderful if MS would consider this.
Forza Milan!
Colt45, to get his scenario working, you would need to explicitly register the hidden field that stores the compressed value of viewstate with ScriptManager, so that the framework would know that it needs to send the updated value for this to the client during an async post-back. I am guessing that you currently use Page.ClientScript.RegisterHiddenField(...) to render your compressed view state. Change this to ScriptManager.RegisterHiddenField(...)
This should fix your issue.
Hope that helps!
Thank you very much, kashif
It works well now...
Sorry...my previous post was wrong...it doesn't work!
I' ve used the ScriptManager.RegisterHiddenField as you suggest but nothing changed.
I need a solution because the viewstate compression is a usefull feature that I don't want to give up, as like as I don't with Ajax...
It did not work for me either.
Most of the problems I see are occuring in GridViews with paging and/or sorting. For example, I have a sorting routine that sorts ASC the first time the header is clicked and then DESC if it is clicked again. The value is stored in ViewState. The first time I click the header, the columns sorts ASC as expected. At this point, "ASC" is stored in ViewState so that when the header is clicked again, I can check this value and then sort by the reverse ("DESC"). However, the grid sorts ASC with every click because the new value is not persisting.
Paging also causes problems. The page data will refresh on the screen correctly between pages 1, 2, 3 etc. However, if I click a button in the 3rd row on the 3rd page that is supposed to update that customer record, it will actually retrieve the customer record that is on the 3rd row of the 1st page. In other words, Ajax always thinks the grid is on the 1st page even though the data on the screen reflects the 3rd page.
If I turn off compressing/caching ViewState, it works fine.
If I leave compression/caching enabled, but turn of Ajax, it works fine.
But together, the marriage fails.
protected override void SavePageStateToPersistenceMedium(Object pViewState)
{
Pair pair1;
System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
Object ViewState;
if (pViewState is Pair)
{
pair1 = ((Pair)pViewState);
pageStatePersister1.ControlState = pair1.First;
ViewState = pair1.Second;
}
else
{
ViewState = pViewState;
}
LosFormatter mFormat = new LosFormatter();
StringWriter mWriter = new StringWriter();
mFormat.Serialize(mWriter, ViewState);
String mViewStateStr = mWriter.ToString();
byte[] pBytes = System.Convert.FromBase64String(mViewStateStr);
pBytes = Compress(pBytes);
String vStateStr = System.Convert.ToBase64String(pBytes);
pageStatePersister1.ViewState = vStateStr;
pageStatePersister1.Save();
//ClientScript.RegisterHiddenField("__MSPVSTATE", vStateStr);
}
protected override Object LoadPageStateFromPersistenceMedium()
{
System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
//try
//{
pageStatePersister1.Load();
//}
//catch
//{
// return null;
//}
String vState = pageStatePersister1.ViewState.ToString();
byte[] pBytes = System.Convert.FromBase64String(vState);
pBytes = DeCompress(pBytes);
LosFormatter mFormat = new LosFormatter();
Object ViewState = mFormat.Deserialize(System.Convert.ToBase64String(pBytes));
return new Pair(pageStatePersister1.ControlState, ViewState);
}
Using ScriptManager.RegisterHiddenField(...) works fine in Beta 2 as long as you set the first argument as an update panel. The update panel can be empty, and should have its UpdateMode set to Always. UsingFiddler you should be able to see your new viewstate hidden field change appropriately.
Whether this is any better or worse than the code in the previous post, I don't know.
Andy
1protected override object LoadPageStateFromPersistenceMedium()2{3string viewState = Request.Form["__VSTATE"];4byte[] bytes = Convert.FromBase64String(viewState);5bytes = Compressor.Decompress(bytes);6LosFormatter formatter =new LosFormatter();7return formatter.Deserialize(Convert.ToBase64String(bytes));8}9protected override void SavePageStateToPersistenceMedium(object viewState)10{11LosFormatter formatter =new LosFormatter();12StringWriter writer =new StringWriter();13formatter.Serialize(writer, viewState);14string viewStateString = writer.ToString();15byte[] bytes = Convert.FromBase64String(viewStateString);16bytes = Compressor.Compress(bytes);17ScriptManager.RegisterHiddenField(this.updVS,"__VSTATE", Convert.ToBase64String(bytes));18}
Hi,
I to am experiencing this problem, i'm using Ajax RC1. I would take the option to use the scriptmanager but i have 2 major problems with this solution, i have a master page that contains the scriptmanager, and i want to apply this to all my existing pages. How can i reference the scriptmanager on the master page from the base class? If at all possible?
Kind regards,
Pedro Costa
Useshunzimm solution above. A slightly modified version of it worked well for me. I have ScriptManager on my master page and it works fine.
This might perhaps be due to changes in the ajax framework, but I've found that you do not need a update panel for ScriptManager.RegisterHiddenField() to work. I just used this as the first param and everything seems okay so far.
Thanks for this post, fixed my issue too with using scriptmanager. One question I have is does it buy anything to have this viewstate compression code on top of IIS 6 HTTP Compression or does http compression make this code obselete?
I've been trying to use the compression code in my application and I'm finding that it's causing problems with a few gridviews that I'm using. What's happening is that the 'OnRowUpdating' and the 'OnRowCancelingEdit' events are not being fired. I have an 'update' and 'cancel' LinkButton inside an 'EditItemTemplate' tag in a 'TemplateField'. The 'OnRowEditing' and the 'OnRowDeleting' events are being fired, but not the other two. Do you have any idea why this might be happening? Any help would be greatly appreciated.
No comments:
Post a Comment