Getting the generated name attribute for use in JavaScript

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Getting the generated name attribute for use in JavaScript

    As most of us probably know, ASP.NET controls do not use an exact copy of a
    control's ID for the HTML element's name or id attribute. When generating
    JavaScript as part of a control or event, we need to have a way to reference
    the HTML elements. The only way I have found to reference the HTML elements
    in my generated Javascript is the following:

    "document.getElementById('" & Me.ctrl.ClientID & "')"

    However, this seems like a lot of extra code for each element. Why do the
    controls have a ClientID property but not a ClientName property? If there
    were a ClientName property, wouldn't it make the code a lot less complicated
    and shorten the amount of JavaScript that had to be included with each
    control? Or is this just one of those Microsoft things where they are trying
    to get people to use the id attribute rather than the name attribute?
    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. unable to execute a javascript in a dynamically generated HTML
      Hi, I have a dynamically generated HTML code rendered on a browser instance created though code (AxSHDocVw.AxWebBrowser instance) . I have...
    2. Javascript Generated Select box
      I hope someone can see something in this code that neither I nor my fellow developers are perceiving. The code below generates a list of states...
    3. embeding Javascript src attribute in User control
      I have a System.Web.UI.UserControl as custom control. I have a javascript block for user control. The problem is I want to bring src attribute from...
    4. Amrita and programmatically-generated JavaScript
      I'm still in the middle of porting my PHP-based web thinking into a ruby frame of mind. I'm looking into amrita for my templating engine but I am...
    5. [Serializable] attribute on generated classes
      Hi, I'm passing a complex type, which I have defined, via a web service method....in the client generated reference.cs I want the class to be...
  3. #2

    Default Re: Getting the generated name attribute for use in JavaScript

    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in
    news:ecZHJ8qCHHA.4740@TK2MSFTNGP03.phx.gbl:
    > Why do the
    > controls have a ClientID property but not a ClientName property? If
    > there were a ClientName property, wouldn't it make the code a lot less
    > complicated and shorten the amount of JavaScript that had to be
    > included with each control? Or is this just one of those Microsoft
    > things where they are trying to get people to use the id attribute
    > rather than the name attribute?
    >
    You can potentially have two objects using the same ClientName - i.e.:

    Form
    +MyLabel
    +MyUserControl
    +MyLabel

    Thus the Form can have a MyLabel and a MyUserControl MyLabel... so if you
    were to refer to MyLabel, which label is it? :-)

    But in anycase, you *could* refer to objects by name ... if you know the
    exact layout of the page. If you take a close look at the element IDs,
    they're generated the same each time (provided the control nesting does not
    change).
    Spam Catcher Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139