Creating Resources Client Side

7 posts, 0 answers
  1. Aaron LaMontagne
    Aaron LaMontagne avatar
    2 posts
    Member since:
    Sep 2008

    Posted 01 Jan 2010 Link to this post

    I'm attempting to create resources via client-side code. I've tried several approaches and I'm not certain why they haven't worked.

    First. I tried creating a web method that returned a Telerik.Web.UI.Resource object:

        [WebMethod] 
        public static Telerik.Web.UI.Resource GetResource() 
        { 
            Telerik.Web.UI.Resource r1 = new Telerik.Web.UI.Resource("Employee", "100", "Frank Sminth"); 
            return r1; 
        } 
     

    and then using this method per the documentation:

     $("#AddResource").click(function() { 
                                    var scheduler = $find("<%=RadScheduler1.ClientID %>"); 
                                    if (scheduler == null) alert("No Control"); 
                                    $.ajax({ 
                                        type: "POST", 
                                        url: "Default.aspx/GetResource", 
                                        data: "{}", 
                                        contentType: "application/json; charset=utf8", 
                                        dataType: "json", 
                                        success: function(r1) { 
                                            scheduler.SchedulerResourceCollection.add(r1); 
                                            scheduler.Rebind(); 
                                            alert("OK"); 
                                        } 
                                    }); 
                                }); 

    However, the alert is never executed and the resource doesn't appear.

    I've also tried creating an entire collection of resources and passing them back:

        [WebMethod] 
        public static Telerik.Web.UI.ResourceCollection GetResource() 
        { 
            Telerik.Web.UI.ResourceCollection rc = new Telerik.Web.UI.ResourceCollection(); 
            Telerik.Web.UI.Resource r1 = new Telerik.Web.UI.Resource("Employee", "100", "Frank Sminth"); 
            rc.Add(r1); 
            return rc; 
        } 

    And here is the JavaScript code to display the resource:
    $("#AddResource").click(function() { 
                                    var resource = new Telerik.Web.UI.SchedulerResource(); 
                                    var scheduler = $find("<%=RadScheduler1.ClientID %>"); 
                                    if (scheduler == null) alert("No Control"); 
                                    $.ajax({ 
                                        type: "POST", 
                                        url: "Default.aspx/GetResource", 
                                        data: "{}", 
                                        contentType: "application/json; charset=utf8", 
                                        dataType: "json", 
                                        success: function(rc) { 
                                            scheduler.set_resources(rc); 
                                            alert("OK"); 
                                        } 
                                    }); 
                                  }); 

      But this isn't working either.

    So, I'm looking for two things.  FIrst, an explanation on how to add a resource via client-side code.  And secondly, where can I find some good documentation for the client-side methods.  The help file that get's shipped with the controls is rather...thin,

    Thanks much!

  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 06 Jan 2010 Link to this post

    Hello Aaron,

    Adding resources on the client is done in the following way:

    // ...
     
    var resource = new Telerik.Web.UI.SchedulerResource();
    resource.set_text("Resource 1");
    resource.set_key("1");
    resource.set_type("1");
     
    scheduler.get_resources().add(resource);
     
    // ...

    But I'm not quite sure what's your intent here. The added resources will not be automatically visible to the end-user as they're already rendered by the server-side code.

    Can you please give us more details on what you're trying to achieve?

    All the best,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 06 Jan 2010 Link to this post

    So how do you programmatically add them in the code-behind?  radScheduler1.resources and radScheduler1.resourceTypes are both read-only according to VS IntelliSense.

    Cheers!
    Mark
  5. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 06 Jan 2010 Link to this post

    Uh, I found some documentation dated Nov 2008 that creates the resourceType in the Page_Load method:
    Dim resourceType As New ResourceType( "Rooms" )  
    resourceType.DataSource = dsRooms 
    resourceType.ForeignKeyField = "RoomID" 
    resourceType.KeyField = "ID" 
    resourceType.TextField = "RoomName" 
    radScheduler1.ResourceTypes.Add( resourceType ) 

    Then, the doc directs the creation and addition of a Resource object to the Appointment Resources collection before inserting the appointment:
    appointment.Resources.Add( New Resource( "Rooms", 1, "Resource text" )) 

    Please tell me where the resource key (1) and the resource text comes from?

    Thanks,
    Mark
  6. Aaron LaMontagne
    Aaron LaMontagne avatar
    2 posts
    Member since:
    Sep 2008

    Posted 08 Jan 2010 Link to this post

    Thanks for the response.  I'm mostly trying to understand the client-side model of the control; I'd like to try and do more via jQuery and less with the server-side events.  For example, my client uses a drop down box to select stores and when the store changes, the employees get listed as resources.  I'm just trying to change the display on the client side by making an AJAX call and then updating the control.  According to the help file, there is a scheduler resource collection object that has an add method.  I was hoping to use that to change the display via client side code.

    What I don't understand is how the help file can speak about these client-side objects and their functionality, but they don't seem to work.  Is there any in-depth documentation for the client-side objects?

    Thanks again for your time!
  7. T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 13 Jan 2010 Link to this post

    Hello Aaron,

    The client-side API of RadScheduler is limited to mostly read-only access by design. Implementing all of the properties on the client will be an overkill in terms of effort and performance.

    Looks like your scenario is similar to the problem described in this KB:
    http://www.telerik.com/support/kb/aspnet-ajax/scheduler/related-load-on-demand-radcomboboxes-in-the-advanced-form-of-radscheduler.aspx

    We acknowledge that the client-side API documentation is a bit on the light side, but we have a nice surprise for the Q1 release that will greatly help with client-side development. We'll provide updated client-side documentation fully integrated with Visual Studio Intellisense. More on that later.

    Mark, this example demonstrates how to add resources from code-behind:
    http://demos.telerik.com/aspnet-ajax/scheduler/examples/bindtolist/defaultcs.aspx

    The key values are arbitrary. Choose whatever makes most sense.

    I hope this helps.

    All the best,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 13 Jan 2010 Link to this post

    Like Aaron, I am trying to do more with JQuery on the client side; isn't that what AJAX is all about?  I bet a lot of developers would appreciate Telerik investing a major effort at producing a clear and comprehensive client API.

    Cheers!
    Mark
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017