Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pete 213 posts 285 karma points
    Oct 27, 2012 @ 13:27
    Pete
    0

    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

     

  • Tommy Albinsson 121 posts 254 karma points
    Oct 29, 2012 @ 14:21
    Tommy Albinsson
    0

    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.

    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.

  • Pete 213 posts 285 karma points
    Oct 31, 2012 @ 18:59
    Pete
    0

    Thanks tommy, I've made a updatepanel example, and going to try your WebMethod as well, some good learning going on.

    cheers, pete

  • Tommy Albinsson 121 posts 254 karma points
    Nov 01, 2012 @ 08:57
    Tommy Albinsson
    0

    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.

  • Pete 213 posts 285 karma points
    Nov 02, 2012 @ 12:03
    Pete
    0

    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.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Nov 03, 2012 @ 17:16
    Bo Damgaard Mortensen
    0

    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

  • Tommy Albinsson 121 posts 254 karma points
    Nov 05, 2012 @ 09:11
    Tommy Albinsson
    0

    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.

    var webMethod = "http://thewebservice/WebService.asmx/filterresults";
    var value = "value";
    var parameters = "{'args':'" + value + "'}";
    
        $.ajax({
            type: "POST",
            url: webMethod,
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {    
                alert(msg.d);
            },
            error: function(e){
                alert("error");              
            }
        });
    
    

    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

Please Sign in or register to post replies

Write your reply to:

Draft