Custom Attribute Checkbox

14 posts, 0 answers
  1. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2009

    Posted 05 May 2009 Link to this post

    I've been able to add a custom attribute to the advance form and works fine. However, instead of a textbox I would like to be able to show a checkbox to hold the boolean value. How can I go about making this custom attribute a checkbox?

    Thanks
  2. Yana
    Admin
    Yana avatar
    5043 posts

    Posted 06 May 2009 Link to this post

    Hello Nick,

    You should set the checked state of the checkbox in the FormCreated event handler like this:

    protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)  
        {  
       
            if (e.Container.Mode == SchedulerFormMode.AdvancedEdit)  
            {  
                CheckBox ch = (CheckBox)e.Container.FindControl("CheckBox1");  
                ch.Checked = System.Convert.ToBoolean(e.Appointment.Attributes["CustomAttribute"]);  
            }  
        } 

    CustomAttribute should be set to "true" or "false" in order to be converted to boolean.

    Kind regards,
    Yana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2009

    Posted 06 May 2009 Link to this post

    Thank you for the response. I tried adding this to my code and I'm now getting a 'Object reference not set to an instance of an object', 'NullReferenceExceptoin'. My custom attribute is called 'IsPublic'. It shows a value of True in the Custom Attribute text box that was generated.

    I recieve the error on the second line of this code:
    CheckBox ch = (CheckBox)e.Container.FindControl("CheckBox1");
    ch.Checked = System.
    Convert.ToBoolean(e.Appointment.Attributes["IsPublic"]);

    This code for the Custom Attribute works, it just that I need it as a check box and not a text box:
     TextBox attrIsPublicTextBox = (TextBox)e.Container.FindControl("AttrIsPublic");


    Thanks for the help.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  4. Yana
    Admin
    Yana avatar
    5043 posts

    Posted 08 May 2009 Link to this post

    Hi Nick,

    I'm sorry for not explaining clear enough.

    A checkbox with the same ID should be placed in a form template, for example AdvancedEditTemplate:

    <AdvancedEditTemplate> 
        <asp:CheckBox ID="CheckBox1" runat="server" />        
    </AdvancedEditTemplate>      

    so you'll be able to find the checkbox in the FormCreated event handler and set its checked state as I showed you in my previous post. 

    Sincerely yours,
    Yana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Deepa Balasundaram
    Deepa Balasundaram avatar
    34 posts
    Member since:
    Jul 2009

    Posted 29 Oct 2009 Link to this post

    Hello,

    Even I want to implement the same functionality as explained by Nick. I am not getting any error messages. But the advanced edit form is not displayed.

    Please suggest me some solutions.

    Thanks,
    Deepa
  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 03 Nov 2009 Link to this post

    Hello Deepa,

    Can you send us the code of your implementation so we can test it?

    Kind regards,
    Peter
    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.
  7. Deepa Balasundaram
    Deepa Balasundaram avatar
    34 posts
    Member since:
    Jul 2009

    Posted 03 Nov 2009 Link to this post

    Hello Peter,

    I have a field called "IsPrivate" to be associated with each appointment and I want this field to appear as a checkbox in the appointment edit form.

    IsPrivate is one of the fields in my "events" table in the database. Each event has this field. When I use ResourceType, it pulls values of IsPrivate for all the events in the "events" table. I want the value of the "IsPrivate" to appear only once and it should be the IsPrivate value associated with that particular event.

    I would like to implement "IsPrivate" in a way that we implement CustomArrtibutes using "CustomAttributeNames". I dont't know how to use "BooleanAttributeControl". I followed the instructions in the following link http://www.telerik.com/help/aspnet-ajax/schedule_advancedformtemplate.html But still I couldn't implement BooleanAttributeControls. Could you please send me "AdvancedFormTemplate" files which I can use to replace the existing "AdvancedFormTemplates" and implement BooleanAttributes?

    Thank you,
    Deepa
  8. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 06 Nov 2009 Link to this post

    Hi Deepa,

    Attached is a demo. Let us know if you have questions.


    All the best,
    Peter
    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.
  9. Deepa Balasundaram
    Deepa Balasundaram avatar
    34 posts
    Member since:
    Jul 2009

    Posted 09 Nov 2009 Link to this post

    Hello Peter,

    Thank you very much. It works fine. But when I check on "AllDayEvet" or "Recurrence" checkbox the corresponding panels are not displayed.

    Please suggest me some solution.

    Thanks,
    Deepa
  10. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 12 Nov 2009 Link to this post

    Hi Deepa,

    We've managed to track down the issue down to the advanced form initialization code in the example. The template object is not recreated after an AJAX update. Here's the fixed code (changes in bold):

    // Dictionary containing the advanced template client object
    // for a given RadScheduler instance (the control ID is used as key).
    var schedulerTemplates = {};
     
    function schedulerFormCreated(scheduler, eventArgs) {
        // Create a client-side object only for the advanced templates
        var mode = eventArgs.get_mode();
        if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
            mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
            // Initialize the client-side object for the advanced form
            var formElement = eventArgs.get_formElement(); 
            var templateKey = scheduler.get_id() + "_" + mode;
            var advancedTemplate = schedulerTemplates[templateKey];
            if (!advancedTemplate)
            {
                // Initialize the template for this RadScheduler instance
                // and cache it in the schedulerTemplates dictionary
                var schedulerElement = scheduler.get_element();
                var isModal = scheduler.get_advancedFormSettings().modal;
                advancedTemplate = new window.SchedulerAdvancedTemplate(schedulerElement, formElement, isModal);
                advancedTemplate.initialize();
     
                schedulerTemplates[templateKey] = advancedTemplate;
     
                // Remove the template object from the dictionary on dispose.
                scheduler.add_disposing(function() {
                    schedulerTemplates[templateKey] = null;
                });
            }
     
            // Are we using Web Service data binding?
            if (!scheduler.get_webServiceSettings().get_isEmpty()) {
                // Populate the form with the appointment data
                var apt = eventArgs.get_appointment();
                var isInsert = mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert;
                var editSeries = eventArgs.get_editingRecurringSeries();
                advancedTemplate.populate(apt, isInsert, editSeries);
            }
        }
    }



    All the best,
    Peter
    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.
  11. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 17 Apr 2013 Link to this post

    An old thread, and not the same problem, but as I have reproduced my problem in the demo attached by Peter I chose to continue on this thread in stead of starting a new one.

    I would like to set the (in this case) IsPrivate attribute to True at start up when adding a new appointment, but I can't get it to work. Please enlighten me.


    Regards, Jill-Connie Lorentsen
  12. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 22 Apr 2013 Link to this post

    Hello Jill,

     
    You ca set the initially set value of the Checkbox by changing the following code in the BooleanAttributeControl.ascx.cs file:

    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
      public string Value
      {
          get
          {
              return AttributeValue.Checked.ToString();
          }
     
          set
          {
              if (string.IsNullOrEmpty(value))
              {
                  AttributeValue.Checked = true;
              }
              else
              {
                  AttributeValue.Checked = Convert.ToBoolean(value);
              }
          }
      }

    Hope this will be helpful.

    All the best,
    Plamen
    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.
  13. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 25 Apr 2013 Link to this post

    I have tried that, but I have two BooleanAttributeControls, and I want one to be default false and the other to be default true. In this case both are default true.

    By setting break points it seems like the code is hit twice for each control, first with Value=True/False and then with Value="".

    So, if I modify the code like shown below I get the desired behaviour, but is it the right way to do it?

    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
        public string Value
        {
            get
            {
                return AttributeValue.Checked.ToString();
            }
     
            set
            {
                if (!string.IsNullOrEmpty(value))          
                {
                    AttributeValue.Checked = Convert.ToBoolean(value);
                }
            }
        }


    Another thing, - having set break points I notice that they are hit when clicking Cancel on the advanced form. Is that correct?

    Regards, Jill-Connie Lorentsen
  14. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 25 Apr 2013 Link to this post

    Hi Jill,

     
    In case you have two checkboxes and they have to have different default value you will have to instantiate different user controls.

    As for the other issue you mentioned -this is the default behavior of the advanced template form in RadScheduler.

    hope this will information will be helpful.

    Regards,
    Plamen
    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