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

Get a Custom Control when Inserting new Appointment

8 Answers 141 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 09 Feb 2009, 03:38 PM
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

8 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 10 Feb 2009, 09:22 AM
Any Suggestions guys?
0
Joseph
Top achievements
Rank 1
answered on 11 Feb 2009, 12:05 PM
Any ideas?
0
Peter
Telerik team
answered on 11 Feb 2009, 03:45 PM

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.
0
Joseph
Top achievements
Rank 1
answered on 11 Feb 2009, 03:47 PM
Thanks a lot man.
0
Lukrs
Top achievements
Rank 2
answered on 18 Feb 2009, 11:22 PM
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



0
Peter
Telerik team
answered on 19 Feb 2009, 08:46 AM
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.
0
Lukrs
Top achievements
Rank 2
answered on 19 Feb 2009, 11:06 AM
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?

0
Peter
Telerik team
answered on 19 Feb 2009, 01:38 PM

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.
Tags
Scheduler
Asked by
Joseph
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Peter
Telerik team
Lukrs
Top achievements
Rank 2
Share this question
or