When I update a property value on Document.AfterSave, the change is not immediately visible on the screen? Anyone know how to update the screen as well?
eg. I have this code to remove domain name from links.
Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
private void Document_AfterSave(Document sender, SaveEventArgs e) { string httpDomain = "http://" + HttpContext.Current.Request.Url.Host + "/"; foreach (Property p in sender.GenericProperties) { p.Value = p.Value.ToString().Replace(httpDomain, "/").Trim(); // Updated but not visible immediately } }
After clicking Save, it's still showing the old value. You have to refresh the page to see the new value.
How do you force Umbraco to update the screen after you change the value?
If you go to the media section and you upload an Image the label properties (for example size) get updated immediately. Don't know if it's using an event, but it might be good to have a look at the source code to see how that works. This is a pretty new feature so it's best to check the source of one of the latest Umbraco versions.
It's not possible without some extra steps, the textbox still retains its old value before the postback. I think the labels in the Media section are updated by the Upload datatype which saves the properties to the DB in addition to using something like Page.FindControl to update the displayed values. Maybe something like that will work for you. Or maybe you could use a custom datatype and play with the events to populate its value.
Also, why not use a content picker instead if you're just linking to pages in the same site? If you also want to give hte ability to have an external URL you can use the Url Picker datatype from uComponents, which allows the user to choose between picking content/media or entering a URL.
I wasn't aware about UrlPicker, will look at that, thanks!
EDIT: UrlPicker doesn't strip domain name either so I'll have to do the same thing lol. The user may want to paste URLs like this http://domain.com/shop.aspx?id=2301 so Content picker doesn't work in this case
Updating property value on Save
When I update a property value on Document.AfterSave, the change is not immediately visible on the screen? Anyone know how to update the screen as well?
eg. I have this code to remove domain name from links.
After clicking Save, it's still showing the old value. You have to refresh the page to see the new value.
How do you force Umbraco to update the screen after you change the value?
Thankyou in advance.
Anyone knows? Is it even possible?
If you go to the media section and you upload an Image the label properties (for example size) get updated immediately. Don't know if it's using an event, but it might be good to have a look at the source code to see how that works. This is a pretty new feature so it's best to check the source of one of the latest Umbraco versions.
Jeroen
It's not possible without some extra steps, the textbox still retains its old value before the postback. I think the labels in the Media section are updated by the Upload datatype which saves the properties to the DB in addition to using something like Page.FindControl to update the displayed values. Maybe something like that will work for you. Or maybe you could use a custom datatype and play with the events to populate its value.
Also, why not use a content picker instead if you're just linking to pages in the same site? If you also want to give hte ability to have an external URL you can use the Url Picker datatype from uComponents, which allows the user to choose between picking content/media or entering a URL.
-Tom
Thank you Jeroen and Tom!
I wasn't aware about UrlPicker, will look at that, thanks!
EDIT: UrlPicker doesn't strip domain name either so I'll have to do the same thing lol. The user may want to paste URLs like this
http://domain.com/shop.aspx?id=2301
so Content picker doesn't work in this case
This no longer works on Umbraco 6?
I can no longer change property values on Save??
This line is executed but seems to do nothing
EDIT: I now have to use ContentService, it is now a lot harder to set a property value. The above line becomes:
If I miss anything, please let me know.
is working on a reply...