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

Attempting to pass data through WebControl Attributes

2 Answers 141 Views
Editor
This is a migrated thread and some comments may be shown as answers.
LeBear
Top achievements
Rank 1
LeBear asked on 23 Jul 2012, 01:30 AM
I have created a number of controls that inherit from standard web controls.  I pass data from the server to the client by doing a MyWebControl.Attributes.Add("Name","Value"), then on the client, I do a MyControl.getAttribute("Name") to get the value.

This doesn't work for the RadEditor.  Is there a similar mechanism I can use to do this with the RadEditor?  What about other RadControls?

Thank you.

2 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 23 Jul 2012, 05:16 PM
Hi Barry,

RadControls for ASP.NET AJAX, as well as RadEditor, use custom rendering and applying custom attributes to be passed to the client is not recommended approach.

In general, when custom attribute is added to the control's attributes collection it is added to the HTML element representing the control on the page - the case with RadEditor, this custom attribute is applied to the controls wrapper <div> element and you can access it using the following approach:

Code-Behind:
RadEditor1.Attributes.Add("customAttribute", "caValue");

ASPX:
var editor = $find("<%=RadEditor1.ClientID %>"); //get reference to the editor's client-side object
var editorWrapper = editor.get_element(); //get editor's wrapper div
 
alert(editorWrapper.getAttribute("customAttribute")); //access the custom attribute

For your convenience I have attached sample page demonstrating this approach.

In addition, please note that not every RadControl will honor custom attributes in this manner.

Greetings,
Dobromir
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
LeBear
Top achievements
Rank 1
answered on 24 Jul 2012, 07:23 PM
Thank you!

Initially, I tried this and it didn't work.  I wonder if I just didn't have something spelled wrong because it works just fine.

I understand about this not being a recommended approach, but it makes my job easier to be able to do this.  I actually have a client-side function that I call to register each input control.  This function is called via a server-side startup script.  At this point, I can pass anything I want, so I can certainly pass the data I need.  However, I've been adding functionality, and being able to have some data come along for the ride almost automatically makes less coding for me.

Thanks again.
Tags
Editor
Asked by
LeBear
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
LeBear
Top achievements
Rank 1
Share this question
or