Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jerry 23 posts 73 karma points
    Mar 31, 2013 @ 06:01
    Jerry
    0

    how to get the element id in Marco.

     Hi all 

    I need to create a wyswyg editor in my macro, but when i put it on frontend, the element id changes, so i can not taegeting the textarea box, 

    <textarea name="ctl00$ctl00$ctl00$ContentPlaceHolderDefault$cp_content$TinyEditor_3$editing" rows="2" cols="20" id="ContentPlaceHolderDefault_cp_content_TinyEditor_3_editing" style="width: 800px; height: 400px"></textarea>

    how  Name and id generated?

    and

    how can i get the element id? i need to run javascript on it.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 31, 2013 @ 08:18
    Tom Fulton
    1

    Hi,

    The IDs get generated by ASP.NET automatically.  I'd probably suggest adding a class to your control and targeting it that way instead.  Otherwise, look into ClientIdMode - set this to Static to tell ASP.NET not to touch the ID of that control.

    Hope this helps,
    Tom 

  • Jerry 23 posts 73 karma points
    Mar 31, 2013 @ 09:05
    Jerry
    0

    Thank you, so there is no build in class in umbraco for it ?

    can i using somthing like umbraco.library.GetXmlNodeCurrent()(or content node)+current macro name + macro Id + real id 

    to make my own?

    Note: I don't know much about umbraco api. 

    any where good to start? 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 31, 2013 @ 11:05
    Jan Skovgaard
    1

    Hi Jerry

    No, there is no built in class in Umbraco that let's you control the rendered id on the elements. It's purely a webforms thing in .net.

    You don't need to make a special combination of some Umbraco things to get a nice id in your case. As Tom says you should simply use the clientid attribute in asp.net - as a supplement to Tom's link you can read this article by Scott Gu where he shows how the client id can be set in different circumstances http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx

    If you don't know where to set the clientid setting in the user control you can set it in the web.config file as Scott shows in the article and then you will see a nice static id.

    Hope this helps.

    /Jan

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 31, 2013 @ 17:57
    Tom Fulton
    0

    Yup, as Jan said there's nothing umbraco-specific going on here, this is all standard .NET stuff.

    You can set the attribute like this:

    <asp:TextBox runat="server" ID="YourId" ClientIDMode="Static" .... />

    You can also set it on a usercontrol level in the directive at the top, or in the web.config where it will take effect on all controls.  I'd probably reccomend doing the attribute as shown above or just using a class to target instead.

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft