Custom datatype: Changes get saved but do not show up on postback
Hey guys,
I have a peculiar problem, that I hope someone can help me with.
Short story:
I've created a custom datatype (using the usercontrol wrapper) that allows users to arrange elements on a page.
When I save or publish the page the values get saved just like they should. However, the changes do not show up on postback - I need to reload the page for the changes to show up.
Long story:
I've created a custom datatype (using the usercontrol wrapper) that allows users to arrange elements on a page. It's a simple grid style layout where you can drag elements around, courtesy of jQuery.sortable.
When the document is saved or published, the new order of elements is saved on the datatype's value property.
The user control in its simplest form:
Page_Load() { if (Page.IsPostBack) { // Save the posted value this.value = Request.Form["myNewValue"].ToString(); } // Render the datatype umbraco.library.RenderTemplate(currentNode.Id); }
- very simple and everything works as expected.
An XSLT macro is responsible for rendering the elements according to the order specified by the custom datatype. This macro is used for rendering content on the frontend as well as within the custom datatype usercontrol. Again, everything works as it should.
The issue is as follows: When I save or publish a document using this datatype, the property gets saved as it should - however, on postback the page shows its previous state, ie. without the changes that were just saved. If I refresh the page the changes show up just fine and the page renders as expected.
Has anybody experienced anything like this? I have a feeling that it has to do with either a) The ViewState not being updated, or b) Something about the page life cycle and me not doing things in the right order - but I'm at loss as to what I can do.
Any help will be greatly appreciated. Thanks in advance! /Mikael
I would think that the RenderTemplate method works on the in-memory (published) content. So one theory could be that your cycle looks a little like this:
1. Editing the page 2. Press publish button 3. Value is saved to db 4. You call RenderTemplate 5. Umbraco publishes the saved content (and puts it in the memory)
Does your datatype actually reflect the changes if you only press save, and the refresh the page?
You're absolutely right, RenderTemplate seems to render the published content, regardless of any unpublished changes. It would be nice to be able to work with unpublished content, but I guess I can live with that.
I also found that:
Page_Load() { if(Page.IsPostBack) { // Save the posted value this.value =Request.Form["myNewValue"].ToString(); }
// "this.value" now holds the updated value... Response.Write(this.value);
// ... but "currentNode.myProperty" does NOT Response.Write(_currentNode.GetProperty("myProperty").Value); }
- which is in line with the cycle that you suggested and sort of explains the behavior I'm experiencing.
So I guess what I need now (not counting the "show unpublished changes" issue) is to make sure that the document is published before I call RenderTemplate.
I tried different combinations of document.Publish(), document.XmlRemoveFromDb(), document.XmlGenerate() - but I'm really just guessing. Any ideas?
But it would be a bit of a dirty process I think, as you will essentially be publishing the document twice each time the publish button is pressed. And also when the "Save" buttons is pressed since that also causes a postback. So it would break the save button.
Explicitly (re-)publishing the document doesn't seem to make any difference, and as you say it wouldn't be the most elegant solution. I'll keep fiddling with it.
As for the other issue, I'm working on extending RenderTemplates() to render a specific version of the document - hopefully that will solve this issue and maybe give me some headway on the other problem.
Thanks again for your feedback, /Mikael - kom så de hvi'e :o)
Custom datatype: Changes get saved but do not show up on postback
Hey guys,
I have a peculiar problem, that I hope someone can help me with.
Short story:
I've created a custom datatype (using the usercontrol wrapper) that allows users to arrange elements on a page.
When I save or publish the page the values get saved just like they should. However, the changes do not show up on postback - I need to reload the page for the changes to show up.
Long story:
I've created a custom datatype (using the usercontrol wrapper) that allows users to arrange elements on a page. It's a simple grid style layout where you can drag elements around, courtesy of jQuery.sortable.
When the document is saved or published, the new order of elements is saved on the datatype's value property.
The user control in its simplest form:
- very simple and everything works as expected.
An XSLT macro is responsible for rendering the elements according to the order specified by the custom datatype. This macro is used for rendering content on the frontend as well as within the custom datatype usercontrol. Again, everything works as it should.
The issue is as follows:
When I save or publish a document using this datatype, the property gets saved as it should - however, on postback the page shows its previous state, ie. without the changes that were just saved. If I refresh the page the changes show up just fine and the page renders as expected.
Has anybody experienced anything like this? I have a feeling that it has to do with either a) The ViewState not being updated, or b) Something about the page life cycle and me not doing things in the right order - but I'm at loss as to what I can do.
Any help will be greatly appreciated. Thanks in advance!
/Mikael
I would think that the RenderTemplate method works on the in-memory (published) content. So one theory could be that your cycle looks a little like this:
1. Editing the page
2. Press publish button
3. Value is saved to db
4. You call RenderTemplate
5. Umbraco publishes the saved content (and puts it in the memory)
Does your datatype actually reflect the changes if you only press save, and the refresh the page?
Hey Morten, thanks for your reply.
You're absolutely right, RenderTemplate seems to render the published content, regardless of any unpublished changes.
It would be nice to be able to work with unpublished content, but I guess I can live with that.
I also found that:
- which is in line with the cycle that you suggested and sort of explains the behavior I'm experiencing.
So I guess what I need now (not counting the "show unpublished changes" issue) is to make sure that the document is published before I call RenderTemplate.
I tried different combinations of document.Publish(), document.XmlRemoveFromDb(), document.XmlGenerate() - but I'm really just guessing. Any ideas?
Thanks,
/Mikael
Take a looke here:
http://umbraco.org/documentation/books/api-cheatsheet
But it would be a bit of a dirty process I think, as you will essentially be publishing the document twice each time the publish button is pressed. And also when the "Save" buttons is pressed since that also causes a postback. So it would break the save button.
Thanks for chiming in again.
Explicitly (re-)publishing the document doesn't seem to make any difference, and as you say it wouldn't be the most elegant solution. I'll keep fiddling with it.
As for the other issue, I'm working on extending RenderTemplates() to render a specific version of the document - hopefully that will solve this issue and maybe give me some headway on the other problem.
Thanks again for your feedback,
/Mikael - kom så de hvi'e :o)
is working on a reply...