Bind a new set of resources on PostBack

8 posts, 0 answers
  1. David
    David avatar
    26 posts
    Member since:
    Aug 2012

    Posted 03 May 2012 Link to this post

    Basically what I'm trying to accomplish with a custom AdvancedForm, is that when the user changes one dropdown value, it will repopulate another. I have a Client dropdown, and clients have services assigned to them. When the client changes, I need to pull in the appropriate services they have based on what comes back from the database.

    Currently I'm using ResourceControl.ascx which is just the single drop-down list. When the resources are initially being populated with the RadScheduler, I set them all to Available = false to hide them until the Client resource's RadComboBox index changes. 

    I am currently using the following code to wire up the desired ComboBox on my AdvancedForm

    RadComboBox cbClient = AdvancedForm.FindControl("ResClient").FindControl("ResourceValue") as RadComboBox;
    //RadComboBox cbClient = e.Container.FindControl("ResClient") as RadComboBox; <- THIS DOESN'T WORK
    if (cbClient != null)
    {
        cbClient.AutoPostBack = true;
        cbClient.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(cbClient_SelectedIndexChanged);
    }

    I've hacked together a solution that partially works, but I am unable to use Attributes or the properties of a Resource 

    protected void cbClient_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        //RadComboBox rcb = (RadComboBox)sender;
        //RadSchedulerAdvancedFormResourceControl ctrl = (RadSchedulerAdvancedFormResourceControl)rcb.Parent;
         
        //Gets the resource control contained within the advanced form
        RadSchedulerAdvancedFormResourceControl resourceControl = AdvancedForm.FindControl("ResService") as RadSchedulerAdvancedFormResourceControl;
        //Grabs the ServiceType combo box for binding
        RadComboBox cbServiceType = AdvancedForm.FindControl("ResService").FindControl("ResourceValue") as RadComboBox;
                 
        //Casts the sender as a RadComboBox, this was the client dropdown
        //RadComboBox cbClient = (RadComboBox)sender;
        //Declare an instance of a ResourceControl to deserialize the key selected
        RadSchedulerAdvancedFormResourceControl resControl = new RadSchedulerAdvancedFormResourceControl();
        //Will rebind the ServiceType dropdown based on who was selected
        //Since items bound to the control can be objects, they need to be serialized/deserialized
        object resourceKey = null;
        if (e.Value != "NULL")
        {
            resourceKey = DeserializeResourceKey(e.Value);
            //Access the provider
            LaSchedulerProvider provider = PopulateProvider();
            //Bind
            cbServiceType.Items.Clear();
            //cbServiceType.DataSource = provider.LoadClientServices(Convert.ToInt32(resourceKey), AdvancedForm.Start, AdvancedForm.End);
            //cbServiceType.DataValueField = "Key";
            //cbServiceType.DataTextField = "Text";
            //cbServiceType.DataBind();
     
            foreach (Resource clientResource in provider.LoadClientServices(Convert.ToInt32(resourceKey), AdvancedForm.Start, AdvancedForm.End))
            {
                clientResource.Available = true;
     
                cbServiceType.Items.Add(new RadComboBoxItem(clientResource.Text, SerializeResourceKey(clientResource.Key)));
            }
            cbServiceType.Items.Insert(0, new RadComboBoxItem("-", "NULL"));
        }
        else
        {
            resourceKey = "";
            cbServiceType.Items.Clear();
            cbServiceType.Items.Insert(0, new RadComboBoxItem("-", "NULL"));
        }

    It's involved taking some of the methods from the various controls and making them Public or copying them and just seems really messy.

    Is there ANY way this can be accomplished in a clean manner?
  2. David
    David avatar
    26 posts
    Member since:
    Aug 2012

    Posted 04 May 2012 Link to this post

    My next best solution was doing something along these lines 

    foreach (Resource clientResource in provider.LoadClientServices(Convert.ToInt32(resourceKey), AdvancedForm.Start, AdvancedForm.End))
    {
        foreach (Resource service in RadScheduler1.Resources.GetResourcesByType("Service"))
        {
            if (clientResource.Key.Equals(service.Key))
            {
                service.Available = true;
            }
            else
            {
                service.Available = false;
            }
        }
        //cbServiceType.Items.Add(new RadComboBoxItem(clientResource.Text, SerializeResourceKey(clientResource.Key)));
    }

    My custom public method in the provider is pulling back the assigned services, and then depending if the resource keys match based on the entire scheduler, would make it available.

    There are matches and the resources are being set to Available but they do not show up as available in the RadComboBox ResourceValue that ResourceControl.ascx is using. Any help?!
  3. David
    David avatar
    26 posts
    Member since:
    Aug 2012

    Posted 07 May 2012 Link to this post

    Anyone? I guess what I'm trying to accomplish is called cascading dropdown lists. I have already looked at other forum posts and the Customizing the AdvancedForm Template and haven't been able to figure it out on my own.
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 May 2012 Link to this post

    Hello David,

    While using resources may seem the intuitive choice for this requirement, I recommend you consider using custom attributes for this case. 

    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.
  5. David
    David avatar
    26 posts
    Member since:
    Aug 2012

    Posted 08 May 2012 Link to this post

    As much as I have considered using attributes instead of resources, unfortunately that's not a viable option. I have come across those articles and they have given me a few ideas, but neither have been a solution for me. Each of the resources that I have are part of business rules. Marking resources as Available or accessing the properties of a Resource is extremely helpful in speeding up my development and implementing checks that go along with the application I am building.

    Any other suggestions?

    edit: My latest solution that meets my needs is that when I retrieve the custom services from the database that are assigned to clients, I store the results in a List<Resource> and store it in session. On AppointmentUpdate/Insert, I remove the resource that was selected on the appointment, use a LINQ query to retrieve the resource that I just removed from the list in Session, and add it to the appointment, then run my validation checks. 

    I really hate to use Session to store this information but I'm really left with no other option at this point. Still open to suggestions.
  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 May 2012 Link to this post

    Hello David,

    Thank you for the update.

    As an alternative solution you can consider Using a Data Provider and Sending additional information to the provider to perform filtering of the resources handling ResourcesPopulating. This technique is also used in the Web Service binding demo which allows you to filter appointments by a resource type.

    Please, let me know what you think of this.

    All the best,
    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.
  7. David
    David avatar
    26 posts
    Member since:
    Aug 2012

    Posted 08 May 2012 Link to this post

    That'd be perfect if I can handle ResourcesPopulating for the AdvancedForm. Would it work with the custom AdvancedForm control? Is there a way to work in the client-side handler with the server-side code I already have? 

    From my understanding you can't mix in the web-service and client-side binding with the server-side binding I've already developed for. If that's the case, then my previous solution will most likely be the best case as development is too far along to change the method of data retrieval.

    Essentially I would have to do the calls on the client-side for my second post I made above. Is that possible if I can handle OnResourcesPopulating with the RadScheduler without implementing the web-service to make a call?
  8. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 09 May 2012 Link to this post

    Hello David,

    Yes, this technique of passing extra information to the provider is applicable for any type of data binding (both server and client) and also it is applicable for the custom advanced form. The custom advance form user control simply replaces the default advanced form and this does not interfere with how RadScheduler is populated or its resource type definition.

    As for the other question - "Essentially I would have to do the calls on the client-side for my second post I made above. Is that possible if I can handle OnResourcesPopulating with the RadScheduler without implementing the web-service to make a call?", you can perform server side logic from a client side event using the approach from this help topic. In the AjaxRequest event you can call RadScheduler's Rebind() method if you need to fire the OnResourcesPopulating event again. Just make sure that your RadAjaxManager has a setting that RadAjaxManager updates RadScheduler:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
           <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadScheduler1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
           </AjaxSettings>
       </telerik:RadAjaxManager>
       <telerik:RadScheduler ID="RadScheduler1" runat="server">
       </telerik:RadScheduler>

    I hope this helps.

    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.
Back to Top