Bit of a newbie question but I'm trying to create a custom data type using the umbraco usercontrol wrapper.
Have the following form:
Basically, you can see 3 rows. The first is to create new menu items, the 2nd and third are listings of the existing items. Buttons to the right allow you to save edits, move and delete these existing items.
I can get everything to work as expected however each button press will only perform action within the current view state - if I want it to be permanent I have to press the default save button after each change for it to be permanent and written back to DB.
My question is - how can I (or is it even possible to) declaratively call a method to save changes back to the DB on each of my custom button postbacks, rather than requiring the default save button?
I think I understand what you mean, you just need to declare different click events for each of the buttons, so in your control you would have something like:
At the moment the view gets updated as expected however the Umbraco database value doesn't get updated and if I refresh the page, any changes since pressing the save button at the TOP of page are lost.
Am I just missing an assignment of the Umbraco value in my OnClick method?
So are you saying the data saves fine if you push Save, but you want it to save instead when you click the buttons in your usercontrol? This is how datatypes are designed to work, but I was thinking you might be able to try the above snippet to save the value manually on your button clicks.
umbraco usercontrol wrapper save on postback
Bit of a newbie question but I'm trying to create a custom data type using the umbraco usercontrol wrapper.
Have the following form:
Basically, you can see 3 rows. The first is to create new menu items, the 2nd and third are listings of the existing items. Buttons to the right allow you to save edits, move and delete these existing items.
I can get everything to work as expected however each button press will only perform action within the current view state - if I want it to be permanent I have to press the default save button after each change for it to be permanent and written back to DB.
My question is - how can I (or is it even possible to) declaratively call a method to save changes back to the DB on each of my custom button postbacks, rather than requiring the default save button?
Thanks :)
I think I understand what you mean, you just need to declare different click events for each of the buttons, so in your control you would have something like:
In the codebehind do something like this
protected void UpBtn_Click(Object sender, EventArgs e) { //Do whatever you want to do with saving here. }
If this is not working then you might need to manually hook up the events, this is a simple little page that explains this:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.click.aspx
If this isn't what you mean then please let me know.
Cheers,
Steve
In your click events I suppose you could save the properties manually using the Document API
Thank you Steven and Tom, kind of what I'm looking for but not quite...
I had already implemented the button_OnClick methods as suggested, they're all working fine, updating the view etc
The problem I'm having is that say for example I edit and existing item and click the save button to right of the row:
This is the OnClick method...
protected void EditItem(object sender, EventArgs e)
{
var button = (Button)sender;
var itemID = int.Parse(button.CommandArgument);
var menuItems = GetMenuItemsFromXml(XmlValue.Value);
var parentControl = button.Parent;
menuItems.Where(x => x.ID == itemID).FirstOrDefault().Title = ((TextBox)parentControl.FindControl("ItemTitle")).Text;
menuItems.Where(x => x.ID == itemID).FirstOrDefault().Description = ((TextBox)parentControl.FindControl("ItemDescription")).Text;
menuItems.Where(x => x.ID == itemID).FirstOrDefault().Price = ((TextBox)parentControl.FindControl("ItemPrice")).Text;
XmlValue.Value = GetXmlStringFromMenuItems(menuItems);
BindRepeater(menuItems.OrderBy(x => x.ID).ToList());
}
At the moment the view gets updated as expected however the Umbraco database value doesn't get updated and if I refresh the page, any changes since pressing the save button at the TOP of page are lost.
Am I just missing an assignment of the Umbraco value in my OnClick method?
Thank you again :)
Hi Tim,
So are you saying the data saves fine if you push Save, but you want it to save instead when you click the buttons in your usercontrol? This is how datatypes are designed to work, but I was thinking you might be able to try the above snippet to save the value manually on your button clicks.
-Tom
I think Tom's suggestion sounds sensible
is working on a reply...