Skip to content

Commit 14f78f7

Browse files
github-actions[bot]KB Bot
and
KB Bot
authored
Added new kb article scheduler-customize-attribute-labels (#627)
Co-authored-by: KB Bot <[email protected]>
1 parent 713ee31 commit 14f78f7

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Customize Attribute Labels
3+
description: Learn how to change the labels of custom attributes in the appointment window of RadScheduler for ASP.NET AJAX to display text different from the attribute names.
4+
type: how-to
5+
page_title: Customize Attribute Labels
6+
slug: scheduler-customize-attribute-labels
7+
tags: radsheduler, asp.net ajax, custom attributes, labels, client-side, server-side
8+
res_type: kb
9+
ticketid: 1669411
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadScheduler for ASP.NET AJAX</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>All</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
After updating to a newer version of Telerik UI for ASP.NET AJAX, the custom attributes in the RadScheduler appointment window display their property names instead of the custom labels. Previously, it was possible to override the labels shown in the appointment window by modifying the control's label in the `OnFormCreated` event. In the newer version, this approach does not seem to work. How can the label for a custom attribute, such as `BookedBy`, be changed to display as "Skapad av:" in the appointment window?
30+
31+
This KB article also answers the following questions:
32+
33+
- How do I change the display label for custom attributes in RadScheduler appointments?
34+
- What is the process to customize attribute labels in RadScheduler using ASP.NET AJAX?
35+
- Can I modify the text of a custom attribute label in the RadScheduler appointment window?
36+
37+
## Solution
38+
39+
Due to changes in newer versions, it might be necessary to update the IDs used in the `FindControl` method. To modify the label of a custom attribute in the appointment window, follow these steps:
40+
41+
**Server-side Customization**: Use the `FindControl` method in the `RadScheduler1_FormCreated` event to get the TextBox associated with the custom attribute. However, directly accessing the label from the server side is not possible anymore.
42+
43+
````C#
44+
protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
45+
{
46+
if (e.Container.Mode == SchedulerFormMode.Edit || e.Container.Mode == SchedulerFormMode.AdvancedEdit)
47+
{
48+
RadTextBox textBox = (RadTextBox)e.Container.FindControl("AttrMyAttribute1"); // Adjust the ID accordingly
49+
}
50+
}
51+
````
52+
53+
**Client-side Customization for Label Text**: To change the label text, utilize the `OnClientFormCreated` event. This approach allows you to access and modify the label text from the client side.
54+
55+
Include the client-side event in your RadScheduler definition:
56+
57+
````ASP.NET
58+
<telerik:RadScheduler ID="RadScheduler1" runat="server" CustomAttributeNames="MyAttribute1, MyAttribute2"
59+
OnClientFormCreated="onClientFormCreated">
60+
</telerik:RadScheduler>
61+
````
62+
63+
Then, implement the JavaScript function to modify the label:
64+
65+
````JavaScript
66+
function onClientFormCreated(sender, args) {
67+
let formElement = args.get_formElement();
68+
let label = Array.from(formElement.querySelectorAll("label"))
69+
.find(label => label.textContent.trim() === "MyAttribute1");
70+
71+
label?.textContent = "ew text"
72+
}
73+
````
74+
75+
This solution allows you to customize the label for custom attributes in the RadScheduler appointment window, ensuring that the labels display the desired text instead of the attribute names.
76+
77+
## See Also
78+
79+
- [RadScheduler Overview](https://www.telerik.com/products/aspnet-ajax/scheduler.aspx)
80+
- [Custom Attributes](https://www.telerik.com/products/aspnet-ajax/documentation/controls/scheduler/design-time/custom-resources-and-attributes#custom-attributes)
81+
- [OnClientFormCreated Event](https://www.telerik.com/products/aspnet-ajax/documentation/controls/scheduler/client-side-programming/events/onclientformcreated#onclientformcreated)

0 commit comments

Comments
 (0)