I'm just learning about updating content without postback, new for me!. I have 3 dropdownlists which need to look up some nodes and then update content based on their selection without a postback, what would be the best way to do this?
I've seen some references about using umbraco REST/JSON base? At the moment I'm looking at a updatepanel with a gridview and the dropdown controls within it.
You can easily get the document you wan't and update its value property. It all comes down to what you want to save. So in your usercontrol, add a custom save button that you attatch a click event to (via jquery). Or you do a change on the dropdowns, your call.
I would create static method with the [WebMethod] attribute, and then call it with jquery.
C#
[WebMethod]
public static void Method()
{
// do your work
// you can also use parameters in the method to supply it with data
// if so, don't forget to send it in the ajax call
}
aspx site javascript
$(document).ready(function() {
$("#button").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/Method",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// If you return something from the method, it can be accessed via msg.d
}
});
// To prevent the postback
return false;
});
});
This way you have total control on your flow, your own save button or change event. You do not have to use the Save and Publish button in umbraco for this.
Okay, I've got a webmethod set up as a webservice, but when I click my form button I get a
No web service found at: /filterresultshold.asmx.
This is my filterresultshold.cs code
/// <summary> /// Summary description for filterresults /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class filterresultshold : System.Web.Services.WebService {
[System.Web.Services.WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string filterresults(string args) { string[] data = args.Trim().Split(','); string topic = data[0]; string number = data[1]; string month = data[2]; string control = "<umbraco:Macro alias='pdfarchivelist' runat='server' topic='" + topic + "' number='" + number + "' month='" + month + "'></umbraco:Macro>"; //LiteralControl literal = new LiteralControl(control); //PlaceHolder PlaceHolder1 = new PlaceHolder(); //PlaceHolder1.Controls.Add(literal); return control; }
}
I'm basically trying to render a umbraco macro from the webmethod if that's possible? based on the values sent thru from the javascript post.
I think you would benefit from having a look at Umbracos proxy called /base. There's a video or two on umbraco.tv about it, if you're subscribing that is. If not, there's also a few wiki pages here on our about it: http://our.umbraco.org/wiki/reference/umbraco-base
That's bascially what /base is build for: REST CRUD operations.
Update content without postback, best method?
Hi all.
I'm just learning about updating content without postback, new for me!. I have 3 dropdownlists which need to look up some nodes and then update content based on their selection without a postback, what would be the best way to do this?
I've seen some references about using umbraco REST/JSON base? At the moment I'm looking at a updatepanel with a gridview and the dropdown controls within it.
Any help appreciated!
Cheers, Pete
Hi Pete,
An updatepanel seems like a good idea. It also depends on what you want to update. If you look at my final post in this thread.
http://our.umbraco.org/forum/developers/extending-umbraco/35542-Creating-your-own-save-and-publish-?p=0#comment129549
You can easily get the document you wan't and update its value property. It all comes down to what you want to save. So in your usercontrol, add a custom save button that you attatch a click event to (via jquery). Or you do a change on the dropdowns, your call.
I would create static method with the [WebMethod] attribute, and then call it with jquery.
This way you have total control on your flow, your own save button or change event. You do not have to use the Save and Publish button in umbraco for this.
Thanks tommy, I've made a updatepanel example, and going to try your WebMethod as well, some good learning going on.
cheers, pete
You are welcome. I hope it will help you :)
The problem with dropdowns is to make them run C# code on change you have to set the AutoPostBack = true and then the postback occurs.
Just contact me if you wan't any further help.
Okay, I've got a webmethod set up as a webservice, but when I click my form button I get a
This is my filterresultshold.cs code
I'm basically trying to render a umbraco macro from the webmethod if that's possible? based on the values sent thru from the javascript post.
Hi Pete,
I think you would benefit from having a look at Umbracos proxy called /base. There's a video or two on umbraco.tv about it, if you're subscribing that is. If not, there's also a few wiki pages here on our about it: http://our.umbraco.org/wiki/reference/umbraco-base
That's bascially what /base is build for: REST CRUD operations.
All the best,
Bo
First of all, the example i supplied above depends on that you create a regular aspx file and expose the method from it.
But really, it is all the same. I think you are calling your method wrong. If you are using a asmx webservice it should look like this.
You could look at the example that Bo provided, though I think my example is simpler to get going with ;)
Check out this link also, a very simple, easy to follow example to use umbraco base.
http://our.umbraco.org/wiki/reference/umbraco-base/simple-base-samples
is working on a reply...