This is a migrated thread and some comments may be shown as answers.

Resource value not Binding

6 Answers 137 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Colin
Top achievements
Rank 1
Colin asked on 22 Sep 2011, 11:59 PM
Howdy,
I have used this Demo to setup a RadScheduler in an existing project.  Before I added the Advanced Templates as described in the demo, my one Resource (called "Group") was properly setting the value of a RadCombobox when you open the appointment.  Since the change, even though the combobox is created and populated correctly, the actual value will not bind.  Frustration level is fairly high right now as we're trying to integrate this into an existing project and every path I've taken i've run into a brick wall.

We're using a webservice local to the web application to call into another ASP.NET webservice to all the gets/saves/deletes, etc.  Had to jump through a bunch of hoops to make that happen.  I really need the abililty to make the custom templates work... can you please suggest something for me to try?

Best Regards.

6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 23 Sep 2011, 09:40 AM
Hi Colin,

Notice that in the demo we use:

UserID='<%# Bind("User") %>'
RoomID='<%# Bind("Room") %>'

Here "User" and "Room" are the names of the resource types, not fields or column names from the data source.

There is a stand-alone sample with various data sources which you can use for reference -
http://www.telerik.com/community/code-library/aspnet-ajax/scheduler/customize-the-advanced-form-with-the-advanced-template-user-controls.aspx

You can also refer to the help topic -
http://www.telerik.com/help/aspnet-ajax/scheduler-customzing-advanced-form-advanced-templates.html

Let me know is you need further assistance.


Greetings, Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Peter
Telerik team
answered on 23 Sep 2011, 09:49 AM
Hi again Colin,

With Web Service binding, you don't need to bind anything in the .aspx page where RadScheduler is. The AdvancedForm.js code will automatically recognize and handle resources as long as you follow the convention
Res[Resource Name] for ID. There is an example in the help topic ->section on How to use the advanced user controls in Client Side binding mode (Web Services)

Best wishes,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Colin
Top achievements
Rank 1
answered on 23 Sep 2011, 05:46 PM
Thats the part that I'm not understanding... Its a resource, so it shouldn't have to be setup as a custom attribute, correct?
Here's the code I've got so far:
In the ASPX:

<%@ Register TagPrefix="scheduler" TagName="AdvancedForm" Src="EventsCustom.ascx" %>

Then where the control is:

    <telerik:RadScheduler ID="RadScheduler1" runat="server" OnClientAppointmentsPopulating="OnClientAppointmentsPopulating"
        AppointmentStyleMode="Default" SelectedView="WeekView" AllowEdit="true" AllowInsert="true" AllowDelete="true"
        StartEditingInAdvancedForm="true" StartInsertingInAdvancedForm="true"
        OnResourcesPopulating="RadScheduler1_ResourcesPopulating"
        Width="800px">
        <WebServiceSettings Path="SchedulerWebService.asmx" ResourcePopulationMode="ServerSide" />
        <AdvancedForm Modal="true" />
<AppointmentTemplate>
                 <div class="rsAptSubject">
                     <%# Eval("Subject") %>
                 </div>
                 <%# Eval("Description") %>
             </AppointmentTemplate>
             <AdvancedEditTemplate>
                 <scheduler:AdvancedForm runat="server" ID="AdvancedEditForm1" Mode="Edit"
                     Subject='<%# Bind("Subject") %>'
                     Description='<%# Bind("Description") %>'
                     Start='<%# Bind("Start") %>'
                     End='<%# Bind("End") %>'
                     RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                     OrganizationGroupID='<%# Bind("Group") %>' />
             </AdvancedEditTemplate>
             <AdvancedInsertTemplate>
                 <scheduler:AdvancedForm runat="server" ID="AdvancedInsertForm1" Mode="Insert"
                     Subject='<%# Bind("Subject") %>'
                     Start='<%# Bind("Start") %>'
                     End='<%# Bind("End") %>'
                     Description='<%# Bind("Description") %>'
                     RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                     OrganizationGroupID='<%# Bind("Group") %>' />
             </AdvancedInsertTemplate>
    </telerik:RadScheduler>

In the EventsCustom.ascx (AdvancedForm), i've got this resource:

<scheduler:ResourceControl runat="server" ID="ResGroup" Type="Group" Label="Group:" Skin='<%# Owner.Skin %>' />

In the EventsCustom.ascx.cs (Code Behind), this property:

[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public object OrganizationGroupID
{
    get
    {
        return ResGroup.Value;
    }
 
    set
    {
        ResGroup.Value = value;
    }
}

All of this was based on the demo referenced in the initial post in this thread.  Before I added the Advanced Form support, it was populating and saving the resource value properly as part of the Appointment.

Thanks!
0
Peter
Telerik team
answered on 27 Sep 2011, 01:17 PM
Hello Colin,

Yes, that is correct - resources do not have to be set up as custom attributes. The 'magic' comes from the AdvancedForm.js file provided that you have added the "Res" prefix for the ID of the resource control.

_saveResources: function (apt) {      
       var template = this;
       var schedulerResources = this._scheduler.get_resources();
 
       this._scheduler.get_resourceTypes().forEach(function (resourceType) {
           var resourceTypeName = resourceType.get_name();
           var baseName = template._templateId + "_Res" + resourceTypeName + resourceControlSuffix;
           var resourcesOfThisType = schedulerResources.getResourcesByType(resourceTypeName);
 
           if (resourceType.get_allowMultipleValues()) {
               //debugger;
               var checkBoxes = $(String.format("input[id*='{0}']", baseName), this._formElement);
 
               if (checkBoxes.length > 0)
                   apt.get_resources().removeResourcesByType(resourceTypeName);
 
               for (var i = 0; i < checkBoxes.length; i++) {
                   if (checkBoxes[i].checked && resourcesOfThisType.get_count() >= i)
                       apt.get_resources().add(resourcesOfThisType.getResource(i));
               };
           }
           else {
               var dropDown = $find(baseName);
               if (!dropDown)
                   return;
 
               apt.get_resources().removeResourcesByType(resourceTypeName);
 
               if (dropDown.get_selectedIndex() == 0)
                   return;
 
               var selectedValue = dropDown.get_selectedItem().get_value();
               var newResource = schedulerResources.findAll(function (res) {
                   return res.get_type() == resourceTypeName &&
                          res._getInternalKey() == selectedValue;
               }).getResource(0) || null;
 
               if (newResource)
                   apt.get_resources().add(newResource);
           }
       });
   },
 
* * *
 
  _populateResources: function () {
       //debugger;
       var template = this;
       var resourceTypes = this._scheduler.get_resourceTypes();
 
       resourceTypes.forEach(function (resType) {
           var baseName = template._templateId + "_Res" + resType.get_name() + resourceControlSuffix;
 
           if (resType.get_allowMultipleValues()) {
               // Clear the resource checkboxes
               $(String.format("input[id*='{0}']", baseName), this._formElement)
                   .each(function () {
                       this.checked = false;
                   });
           }
           else {
               var dropDown = $find(baseName);
               if (dropDown)
                   dropDown.get_items().getItem(0).select();
           }
       });
 
       this._appointment.get_resources().forEach(function (res) {
           var baseName = template._templateId + "_Res" + res.get_type() + resourceControlSuffix;
           var resType = resourceTypes.getResourceTypeByName(res.get_type());
           if (resType && resType.get_allowMultipleValues()) {
               var resIndex = template._getResourceIndex(res);
               var checkBox = $get(baseName + "_" + resIndex);
 
               if (checkBox)
                   checkBox.checked = true;
           }
           else {
               var dropDown = $get(baseName);
               if (dropDown)
                   template._selectDropDownValue(dropDown, res._getInternalKey());
           }
       });
   },

This obsoletes binding any fields in the aspx page of RadScheduler, so you can simply use the following:
<AdvancedEditTemplate>
                <scheduler:AdvancedForm runat="server" ID="AdvancedEditForm1" Mode="Edit" />
            </AdvancedEditTemplate>
            <AdvancedInsertTemplate>
                <scheduler:AdvancedForm runat="server" ID="AdvancedInsertForm1" Mode="Insert"   />
            </AdvancedInsertTemplate>

If you continue to experience problems, I suggest you isolate the issue in a simple demo and send it via the support ticket you have opened.

Greetings, Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Colin
Top achievements
Rank 1
answered on 27 Sep 2011, 03:11 PM
When I take the binding out, nothing binds at all... I don't even get the combobox values in the resource to populate.
Its going to be very hard to submit a sample since we're grabbing data from a webservice that is not exposed publically.  Any other thoughts?  As you can see from the samples I posted above, I prefaced the resource with "Res"...
0
Peter
Telerik team
answered on 29 Sep 2011, 04:51 PM
Hi Colin,

We were able to run the sample you sent in the support ticket. Here is what we replied in the ticket:

I was able to isolate the problem to the Availability of the resources. Also, I noticed that you didn't handle OnClientFormCreated. You need to hook on the event like this:
Copy Code
* * *
<telerik:RadScheduler ID="RadScheduler1" runat="server" OnClientFormCreated="schedulerFormCreated" .../>
* * *

Strangely, the IncludeResource method in EventsResources.ascx.cs was returning false. I am not sure why was that, but if you don't need any special kind of filtering you can simply comment the if check like this:
Copy Code
private IEnumerable<Resource> GetResources(string resType)
{
List<Resource> availableResources = new List<Resource>();
IEnumerable<Resource> resources = Owner.Provider.GetResourcesByType(Owner, resType);
foreach (Resource res in resources)
{
//if (IncludeResource(res))
//{
availableResources.Add(res);
//}
}
return availableResources;
}

Please, try those two suggestions and let me know how it goes.


Regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Scheduler
Asked by
Colin
Top achievements
Rank 1
Answers by
Peter
Telerik team
Colin
Top achievements
Rank 1
Share this question
or