Get a Custom Control when Inserting new Appointment

9 posts, 0 answers
  1. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 09 Feb 2009 Link to this post

    Hello eveyrone,

    I have created a new DropDownList inside the Insert Form ( normal and advanced mode) inside the FormCreated event.

    Now when a user double click and use the normal or advanced insert form to submit his new Appointment I want to access the DropDownList to get the selected value.

    This will be handled inside the AppointmentInsert event.

    Any ideas?

    Thanks
  2. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 10 Feb 2009 Link to this post

    Any Suggestions guys?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 11 Feb 2009 Link to this post

    Any ideas?
  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 11 Feb 2009 Link to this post

    Hello Joseph,

    This scenario is not possible with a dropdownlist control. However, RadCombobox and its rescuing OnClientSelectedIndexChanged event offer an easy solution. Please, consider the following code:

    aspx:

    <script type="text/javascript">  
           function OnClientSelectedIndexChanged(sender, eventArgs) {  
               var selectedValue = document.getElementById("HiddenField1");  
               selectedValue.value = eventArgs.get_item().get_value();  
           }  
       </script>  
     
        <asp:HiddenField ID="HiddenField1" runat="server" /> 

    C#:

     protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)  
        {  
            if (e.Container.Mode == SchedulerFormMode.AdvancedInsert)  
            {  
                RadComboBox cb1 = new RadComboBox();  
                RadComboBoxItem item1 = new RadComboBoxItem("a""a");  
                RadComboBoxItem item2 = new RadComboBoxItem("b""b");  
                RadComboBoxItem item3 = new RadComboBoxItem("c""c");  
                cb1.Items.Add(item1);  
                cb1.Items.Add(item2);  
                cb1.Items.Add(item3);  
                cb1.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged";  
                Panel advPanel = (Panel)e.Container.FindControl("AdvancedControlsPanel");  
                advPanel.Controls.Add(cb1);  
            }  
        }  
         
        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)  
        {  
            e.Appointment.Subject = HiddenField1.Value.ToString();  
         } 

    So, the idea is to handle the OnClientSelectedIndexChanged of RadCombobox and store the selected value in a hidden field on the client. Then you can access this value in any event you wish by simply using HiddenField1.Value.


    Best wishes,

    Peter
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Joseph
    Joseph avatar
    135 posts
    Member since:
    Sep 2007

    Posted 11 Feb 2009 Link to this post

    Thanks a lot man.
  7. Lukrs
    Lukrs avatar
    39 posts
    Member since:
    Sep 2012

    Posted 18 Feb 2009 Link to this post

    Hi,

    This solution sounds great, but I get an error on the following line:

    advPanel.Controls.Add(cb1);

    Object reference not set to an instance of an object.


    I use the advancededit and insert template also.

    Any ideas?

    Thanks



  8. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 19 Feb 2009 Link to this post

    Hello Luka,

    The solution I suggested assumes that you use the default advanced insert form. If you use templates, then you need to consider what IDs you set for the controls in the template. For example, if you have:

    <AdvancedInsertTemplate> 
        <asp:Panel ID="Panel1" runat="server"> 
        * * * 
        </asp:Panel>
    </AdvancedInsertTemplate>

    Then in FormCreated you would use:

    Panel advPanel = (Panel)e.Container.FindControl("Panel1");


    Kind regards,
    Peter
    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.
  9. Lukrs
    Lukrs avatar
    39 posts
    Member since:
    Sep 2012

    Posted 19 Feb 2009 Link to this post

    yes, but when I add this


     <AdvancedInsertTemplate>
              <asp:Panel ID="advPanela" runat="server">         
              <scheduler:AdvancedInsertForm runat="server" ID="AdvancedInsertForm1"
                                       Subject='<%# Bind("Subject") %>'
                                       Start='<%# Bind("Start") %>'
                                       End='<%# Bind("End") %>'
                                       RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                                       Description='<%# Bind("Description") %>'
                                       UserID='<%# Bind("User") %>'
                                       RoomID='<%# Bind("Room") %>' />
               </asp:Panel>
           </AdvancedInsertTemplate>


    or this


     <AdvancedInsertTemplate>
               
          
             
              
              <scheduler:AdvancedInsertForm runat="server" ID="AdvancedInsertForm1"
                                       Subject='<%# Bind("Subject") %>'
                                       Start='<%# Bind("Start") %>'
                                       End='<%# Bind("End") %>'
                                       RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
                                       Description='<%# Bind("Description") %>'
                                       UserID='<%# Bind("User") %>'
                                       RoomID='<%# Bind("Room") %>' />

    <asp:Panel ID="advPanela" runat="server">         
     </asp:Panel>

           </AdvancedInsertTemplate>

    The advancedInsertForm covers the radComboBox.

    What can I do?

  10. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 19 Feb 2009 Link to this post


    It depends where you want RadCombobox to appear. You can try the following for example:

    <AdvancedInsertTemplate>
    <scheduler:AdvancedInsertForm runat="server" ID="AdvancedInsertForm1"
    Subject='<%# Bind("Subject") %>'
    Start='<%# Bind("Start") %>'
    End='<%# Bind("End") %>'
    RecurrenceRuleText='<%# Bind("RecurrenceRule") %>'
    Description='<%# Bind("Description") %>'
    UserID='<%# Bind("User") %>'
    RoomID='<%# Bind("Room") %>' />
    <asp:Panel ID="advPanela" runat="server">
    </asp:Panel>
    </AdvancedInsertTemplate>

    In this case RadCombobox will appear at the bottom.

    Since you are using the user controls for the advanced form, an alternative is to edit the AdvancedInsertForm.ascx and AdvancedEditForm.ascx  and to include RadCombobox directly there. In this case you will not need to handle FormCreated to add RadCombobox dynamically.


    Greetings,
    Peter
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017