Attempting to pass data through WebControl Attributes

3 posts, 0 answers
  1. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 22 Jul 2012 Link to this post

    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. Dobromir
    Dobromir avatar
    1633 posts

    Posted 23 Jul 2012 Link to this post

    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:

    RadEditor1.Attributes.Add("customAttribute", "caValue");

    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.

    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.
  3. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 24 Jul 2012 Link to this post

    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.
Back to Top