Accessing Custom Attributes in RadSignature Client-Side
Environment
Product | Version |
---|---|
RadSignature for ASP.NET AJAX | all |
Description
I added a custom attribute to my RadSignature control. I want to use the custom attribute on the client side.
This KB article also answers the following questions:
- How can I access a custom attribute of RadSignature in the client-side code?
- What is the correct method to retrieve a custom attribute value from RadSignature using JavaScript?
- Is it possible to use
get_element().getAttribute()
to read custom attributes of RadSignature?
Solution
To access custom attributes of the RadSignature control on the client side, use the get_element().getAttribute()
method. This approach allows you to retrieve the value of any custom attribute that you have added to the RadSignature control.
Here is a step-by-step example showing how to set a custom attribute in the RadSignature control and access it using JavaScript:
-
ASPX Markup: Define the RadSignature control with a custom attribute. Attach a client-side event handler to the
OnLoad
event.<telerik:RadSignature ID="RadSignature1" runat="server"> <ClientEvents OnLoad="OnClientLoad" /> </telerik:RadSignature> <script type="text/javascript"> function OnClientLoad(sender) { alert(sender.get_element().getAttribute("CustomAttribute")); } </script>
-
Code-behind (ASPX.CS): Set the value of the custom attribute in the code-behind file.
RadSignature1.Attributes["CustomAttribute"] = "My Custom Attribute Value";
Accessing the Custom Attribute: The custom attribute can now be accessed client-side using the
OnClientLoad
event handler, as shown in the JavaScript part of the ASPX markup. Theget_element().getAttribute()
method retrieves the value of the custom attribute.
By following these steps, you can successfully access custom attributes of the RadSignature control on the client side.