Scheduler layout problem.

1 Answer 46 Views
Scheduler
Joakim
Top achievements
Rank 1
Joakim asked on 04 Nov 2024, 02:43 PM | edited on 11 Nov 2024, 06:32 AM

Hi,

Been using Telerik UI for ASP.NET AJAX from 2012.
This year we decided to update to newer version.

When we started using the newer version we started having some layout related problems.
We have not made any changes to our code between updating the Telerik package.

When creating an appointment in scheduler we have added three custom attributes, BookedBy, Created and Temperatur.
The three attributes are shown but they show the property name instead of the custom label we have set for the control as shown in third picture.

First picture shows how the GUI have looked so far.
Second picture shows how the GUI looks after changing to the newer version.
Third and fourth pictures are screen dumps of the code.

Thanks in advance for any help you can give.

Edit

I realize my initial post wasn't very clear on my question.

My question is how to get the label of the custom attributes in
the appointment window, to be different from the names given in the telerik:Radscheduler tag.

In the older version of telerik package you could override the label shown in the appointment window.
In earlier version of telerik UI package this was done in the function you set in onformedcreated parameter of telerik:Radscheduler tag,
get the control linked to the custom attribute using following code:

RadTextBox CreatedByTextbox = (RadTextBox)e.Container.FindControl("AttrBookedBy");

and then change the label shown by changing the label of the control:

CreatedByTextbox.Label = "Skapad av:";

However in newer version of telerik UI package this doesn't seem to give the same behavior any more.

In my example I want the custom attribute BookedBy label in appointment window to be shown as "Skapad av:", how would I go about getting this behavior?

1 Answer, 1 is accepted

Sort by
0
Accepted
Vasko
Telerik team
answered on 07 Nov 2024, 12:12 PM

Hi Joakim,

Several breaking changes have occurred over the years (see Known Issues, Important Changes and Changes and Backward Compatibility).

Generally, this is how the custom attributes will look once added by following the steps in the Custom Attributes article:

 <telerik:RadScheduler RenderMode="Lightweight" runat="server" ID="RadScheduler1" DayStartTime="08:00:00"
     CustomAttributeNames="MyAttribute1, MyAttribute2"
     DayEndTime="18:00:00" OnAppointmentInsert="RadScheduler1_AppointmentInsert"
     OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" OnAppointmentDelete="RadScheduler1_AppointmentDelete"
     DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End"
     DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentId"
     DataReminderField="Reminder">
     <AdvancedForm Modal="true" EnableCustomAttributeEditing="true"></AdvancedForm>
     <TimelineView UserSelectable="false"></TimelineView>
     <TimeSlotContextMenuSettings EnableDefault="true"></TimeSlotContextMenuSettings>
     <AppointmentContextMenuSettings EnableDefault="true" ></AppointmentContextMenuSettings>
     <Reminders Enabled="true"></Reminders>
 </telerik:RadScheduler>
private const string AppointmentsKey = "Telerik.Web.Examples.Scheduler.BindToList.CS.Apts";

private List<AppointmentInfo> Appointments
{
    get
    {
        List<AppointmentInfo> sessApts = Session[AppointmentsKey] as List<AppointmentInfo>;
        if (sessApts == null)
        {
            sessApts = new List<AppointmentInfo>();
            Session[AppointmentsKey] = sessApts;
        }

        return sessApts;
    }
}

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    if (!IsPostBack)
    {
        Session.Remove(AppointmentsKey);

        InitializeResources();
        InitializeAppointments();
    }

    RadScheduler1.DataSource = Appointments;
}

protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
{
    Appointments.Add(new AppointmentInfo(e.Appointment));
}

protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
{
    AppointmentInfo ai = FindById(e.ModifiedAppointment.ID);


    RecurrenceRule rrule;

    if (RecurrenceRule.TryParse(e.ModifiedAppointment.RecurrenceRule, out rrule))
    {
        rrule.Range.Start = e.ModifiedAppointment.Start;
        rrule.Range.EventDuration = e.ModifiedAppointment.End - e.ModifiedAppointment.Start;
        TimeSpan startTimeChange = e.ModifiedAppointment.Start - e.Appointment.Start;
        for (int i = 0; i < rrule.Exceptions.Count; i++)
        {
            rrule.Exceptions[i] = rrule.Exceptions[i].Add(startTimeChange);
        }
        e.ModifiedAppointment.RecurrenceRule = rrule.ToString();
    }

    ai.CopyInfo(e.ModifiedAppointment);
}

protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e)
{
    Appointments.Remove(FindById(e.Appointment.ID));
}

private void InitializeResources()
{
    ResourceType resType = new ResourceType("User");
    resType.ForeignKeyField = "UserID";

    RadScheduler1.ResourceTypes.Add(resType);
    RadScheduler1.Resources.Add(new Resource("User", 1, "Alex"));
    RadScheduler1.Resources.Add(new Resource("User", 2, "Bob"));
    RadScheduler1.Resources.Add(new Resource("User", 3, "Charlie"));
}

private void InitializeAppointments()
{
    DateTime start = DateTime.UtcNow.Date;
    start = start.AddHours(6);
    Appointments.Add(new AppointmentInfo("Take the car to the service", start, start.AddHours(1), string.Empty, null, new Reminder(30).ToString(), 1));
    Appointments.Add(new AppointmentInfo("Meeting with Alex", start.AddHours(2), start.AddHours(3), string.Empty, null, string.Empty, 2));
}

private AppointmentInfo FindById(object ID)
{
    foreach (AppointmentInfo ai in Appointments)
    {
        if (ai.ID.Equals(ID))
        {
            return ai;
        }
    }

    return null;
}


class AppointmentInfo {

private readonly string _id;
private string _subject;
private DateTime _start;
private DateTime _end;
private string _recurrenceRule;
private string _recurrenceParentId;
private string _reminder;
private int? _userID;

public string ID
{
    get
    {
        return _id;
    }
}

public string Subject
{
    get
    {
        return _subject;
    }
    set
    {
        _subject = value;
    }
}

public DateTime Start
{
    get
    {
        return _start;
    }
    set
    {
        _start = value;
    }
}

public DateTime End
{
    get
    {
        return _end;
    }
    set
    {
        _end = value;
    }
}

public string RecurrenceRule
{
    get
    {
        return _recurrenceRule;
    }
    set
    {
        _recurrenceRule = value;
    }
}

public string RecurrenceParentID
{
    get
    {
        return _recurrenceParentId;
    }
    set
    {
        _recurrenceParentId = value;
    }
}

public int? UserID
{
    get
    {
        return _userID;
    }
    set
    {
        _userID = value;
    }
}

public string Reminder
{
    get
    {
        return _reminder;
    }
    set
    {
        _reminder = value;
    }
}

private AppointmentInfo()
{
    _id = Guid.NewGuid().ToString();
}

public AppointmentInfo(string subject, DateTime start, DateTime end, string recurrenceRule, string recurrenceParentID, string reminder, int? userID) : this()
{
    _subject = subject;
    _start = start;
    _end = end;
    _recurrenceRule = recurrenceRule;
    _recurrenceParentId = recurrenceParentID;
    _reminder = reminder;
    _userID = userID;
}

public AppointmentInfo(Appointment source) : this()
{
    CopyInfo(source);
}

public void CopyInfo(Appointment source)
{
    Subject = source.Subject;
    Start = source.Start;
    End = source.End;
    RecurrenceRule = source.RecurrenceRule;

    if (source.RecurrenceParentID != null)
    {
        RecurrenceParentID = source.RecurrenceParentID.ToString();
    }

    if (!String.IsNullOrEmpty(Reminder))
    {
        Reminder = source.Reminders[0].ToString();
    }

    Resource user = source.Resources.GetResourceByType("User");
    if (user != null)
    {
        UserID = (int?)user.Key;
    }
    else
    {
        UserID = null;
    }
}

Regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Vasko
Telerik team
commented on 12 Nov 2024, 10:33 AM

Hello,

Due to the changes over the years, it is possible the IDs needed for the FindControl method to have been updated, thus resulting in the issue you're experiencing.

You can get the TextBox associated with the Custom Attribute Name by passing it in the FindControl method:

protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
{
    if (e.Container.Mode == SchedulerFormMode.Edit || e.Container.Mode == SchedulerFormMode.AdvancedEdit)
    {
        RadTextBox textBox = (RadTextBox)e.Container.FindControl("AttrMyAttribute1"); // This is the TextBox's ID
    }
}

Regarding the Label Itself, you cannot access it from the server side anymore, and the best alternative would be to do this on the client-side with the OnClientFormCreated event:

function onClientFormCreated(sender, args) {
    let formElement = args.get_formElement();
    let label = Array.from(formElement.querySelectorAll("label"))
        .find(label => label.textContent.trim() === "MyAttribute1");

    label.textContent = "New Text";
}

Try this approach and see if it will help you out.

Regards,
Author nickname
Progress Telerik

Joakim
Top achievements
Rank 1
commented on 12 Nov 2024, 12:17 PM

Hi Vasko,

This was what I was looking for.
Thank you very much!
Tags
Scheduler
Asked by
Joakim
Top achievements
Rank 1
Answers by
Vasko
Telerik team
Share this question
or