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

Scheduler / Using RadToolTip / No resources / sqldatasource/ DataItem=null problem

3 Answers 49 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 21 Sep 2012, 03:12 PM

Hello,

I'm using RadToolTip in a RadScheduler with sqldatasource and i can see only and empty RadScheduler. Also, when i press the Save button a null reference exception arises in the following line of the Radscheduler1_AppointmentCreated method: string id = e.Appointment.ID.ToString; (The DataItem and the ID are null). The data insert to the database. 

What am i doing wrong;

Thank you very much.

P.S.

I have writthen the following code:

aspx code

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                </Scripts>
            </telerik:RadScriptManager>
            <script type="text/javascript">
 
 
                function hideActiveToolTip() {
                    var tooltip = Telerik.Web.UI.RadToolTip.getCurrent();
                    if (tooltip) {
                        tooltip.hide();
                    }
                }
 
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
                function beginRequestHandler(sender, args) {
                    var prm = Sys.WebForms.PageRequestManager.getInstance();
                    if (args.get_postBackElement().id.indexOf('RadScheduler1') != -1) {
                        hideActiveToolTip();
                    }
                }
 
                function OnClientRequestStart(sender, args) {
                    args.set_cancel(true);
                    var tooltip = Telerik.Web.UI.RadToolTip.getCurrent();
                    if (tooltip) {
                        var element = tooltip.get_targetControl();
                        var apt = $find("<%=RadScheduler1.ClientID %>").getAppointmentFromDomElement(element);
                        $get("startTime").innerHTML = apt.get_start().format("MM/dd/yyyy HH:mm");
                        $get("endTime").innerHTML = apt.get_end().format("MM/dd/yyyy HH:mm");
                        $get("descriptionDiv").innerHTML = apt.get_subject();
                        tooltip.set_text($get("contentContainer").innerHTML);
                    }
                }
 
                function OnClientAppointmentContextMenu(sender, args) {
                    hideActiveToolTip();
                }
            </script>
       
            <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="750px" TimeZoneOffset="03:00:00" EnableDescriptionField="true"
                    SelectedDate="2012-04-16" DayStartTime="08:00:00" DayEndTime="18:00:00" DataSourceID="SqlDataSource1"
                    DataKeyField="ID" DataSubjectField="Subject" DataDescriptionField="Description" DataStartField="Start" DataEndField="End"
                    DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
                    DisplayDeleteConfirmation="true" SelectedView="WeekView" OnClientAppointmentContextMenu="OnClientAppointmentContextMenu" CustomAttributeNames="LastModified, Annotations, User">
                    <AdvancedForm Modal="true" />
                    <TimelineView UserSelectable="false" />
                    <TimeSlotContextMenuSettings EnableDefault="true" />
                    <AppointmentContextMenuSettings EnableDefault="true" />
                </telerik:RadScheduler>
            <telerik:RadToolTipManager runat="server" ID="RadToolTipManager1" Width="320" Height="170"
                Animation="None" HideEvent="Default" Text="Loading..." OnAjaxUpdate="RadToolTipManager1_AjaxUpdate" />
            <div style="display: none;">
                <div id="contentContainer">
                    <div class="appointment-tooltip">
                        <p>
                            Starts on: <span id="startTime">
                                <!-- -->
                            </span>
                            <br />
                            Ends on: <span id="endTime">
                                <!-- -->
                            </span>
                        </p>
                        <hr />
                        Description:
                        <div id="descriptionDiv">
                        </div>
                    </div>
                </div>
            </div>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HumanResourcesConnectionString %>"
                DeleteCommand="DELETE FROM [Schedule] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Schedule] ([Subject], [Description], [Start], [End], [RecurrenceRule], [RecurrenceParentID], [User], [LastModified]) VALUES (@Subject, @Description, @Start, @End, @RecurrenceRule, @RecurrenceParentID, @User, @LastModified)"
                SelectCommand="SELECT * FROM [Schedule]"
                UpdateCommand="UPDATE [Schedule] SET [Subject] = @Subject, [Description]=@Description, [Start] = @Start, [End] = @End, [RecurrenceRule]=@RecurrenceRule, [RecurrenceParentID]=@RecurrenceParentID, [User]=@User, [LastModified]=@LastModified WHERE [ID] = @ID">
                <SelectParameters>
                    <asp:SessionParameter Name="User" SessionField="User" DefaultValue="" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Subject" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Start" Type="DateTime" />
                    <asp:Parameter Name="End" Type="DateTime" />
                    <asp:Parameter Name="ID" Type="Int32" />
                    <asp:Parameter Name="RecurrenceRule" Type="String" />
                    <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                    <asp:Parameter Name="Annotations" Type="String" />
                    <asp:SessionParameter Name="User" SessionField="User" DefaultValue="" />
                    <asp:Parameter Name="LastModified" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Subject" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Start" Type="DateTime" />
                    <asp:Parameter Name="End" Type="DateTime" />
                    <asp:Parameter Name="Annotations" Type="String" />
                    <asp:Parameter Name="RecurrenceRule" Type="String" />
                    <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                    <asp:SessionParameter Name="User" SessionField="User" DefaultValue="" />
                    <asp:Parameter Name="LastModified" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>


aspx.cs code

public partial class _Default : System.Web.UI.Page
{
    
    private void Page_Load(object sender, EventArgs e)
    {
 
        RadScheduler1.AppointmentCreated += RadScheduler1_AppointmentCreated;
        RadScheduler1.DataBound += RadScheduler1_DataBound;
        RadToolTipManager1.OnClientRequestStart = String.Empty;
   
    }
 
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
 
        RadToolTipManager1.TargetControls.Clear();
        ScriptManager.RegisterStartupScript(this, typeof(Page), "HideToolTip", "hideActiveToolTip();", true);
         
         
    }
     
    protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
    {
        if (e.Appointment.Visible && !IsAppointmentRegisteredForTooltip(e.Appointment))
        {
 
           
            string id = e.Appointment.ID.ToString();
 
            
 
            foreach (string domElementID in e.Appointment.DomElements)
            {
                RadToolTipManager1.TargetControls.Add(domElementID, id, true);
            }
        }
    }
 
      protected void RadToolTipManager1_AjaxUpdate(object sender, ToolTipUpdateEventArgs e)
        {
            int aptId;
            Appointment apt;
            if (!int.TryParse(e.Value, out aptId))//The appoitnment is occurrence and FindByID expects a string
                apt = RadScheduler1.Appointments.FindByID(e.Value);
            else //The appointment is not occurrence and FindByID expects an int
                apt = RadScheduler1.Appointments.FindByID(aptId);
 
            AppointmentToolTip toolTip = (AppointmentToolTip)LoadControl("AppointmentToolTip.ascx");
            toolTip.TargetAppointment = apt;
            e.UpdatePanel.ContentTemplateContainer.Controls.Add(toolTip);
        }
 
      protected void RadScheduler1_DataBound(object sender, EventArgs e)
      {
          RadToolTipManager1.TargetControls.Clear();
          ScriptManager.RegisterStartupScript(this, typeof(Page), "HideToolTip", "hideActiveToolTip();", true);
      }
 
 
      private bool IsAppointmentRegisteredForTooltip(Appointment apt)
      {
          foreach (ToolTipTargetControl targetControl in RadToolTipManager1.TargetControls)
          {
              if (apt.DomElements.Contains(targetControl.TargetControlID))
              {
                  return true;
              }
          }
 
          return false;
      }
 
    }




3 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 26 Sep 2012, 12:07 PM
Hi George,

Unless there is some discrepancy with the database itself, you should be able to get the ID of the appointment being created for which the AppointmentCreated event handler is raised.

What you can do, however, is isolate the following demo in a sample page and compare the two versions, yours and the isolated demo's version, so you can be sure you haven't missed anything:  http://demos.telerik.com/aspnet-ajax/scheduler/examples/radtooltip/defaultcs.aspx.

Kind regards,
Ivana
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
George
Top achievements
Rank 1
answered on 01 Oct 2012, 12:46 PM
Hello,

I'm still having the problem! I'm using the same code as in the example (the only difference is that i'm using an SQLDataSouce instead of a SessionDataSource) and the ID is null. Any ideas?

Thank you very much.
0
Ivana
Telerik team
answered on 04 Oct 2012, 07:14 AM
Hello George,

Everything seems just fine with your code. As  I have stated in my previous post there could be some discrepancy with the database itself.

In order to help you with your scenario, I will need a sample project on which the troubled behavior is replicated. Could you please isolate the scenario in question in a runnable sample project and send it over so we would be able to troubleshoot the issues locally?

Thank you!

Regards,
Ivana
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
George
Top achievements
Rank 1
Answers by
Ivana
Telerik team
George
Top achievements
Rank 1
Share this question
or