Copied to clipboard

Flag this post as spam?

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


  • Sherry Ann Hernandez 320 posts 344 karma points
    Feb 01, 2011 @ 15:05
    Sherry Ann Hernandez
    0

    user control is generating different id

    Hi,

    I have a e-mail subscription user control. When using in different page it is generating different id/name. I'm not sure why it is doing that. Event if the two page is under one masterpage.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 01, 2011 @ 15:11
    Jan Skovgaard
    0

    Hi Sherry

    Could you perhaps share some of the code for the user control?

    /Jan

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Feb 01, 2011 @ 20:37
    Richard Soeteman
    1

    Hi Sherry,

    The Id of a usercontrol is dynamic and based on the parentId(s) and the id of the usercontrol itself. Don't assume this id is always the same. This is the way Asp.net works. What do you want to achieve?

    Cheers,

    Richard

  • Sherry Ann Hernandez 320 posts 344 karma points
    Feb 03, 2011 @ 07:55
    Sherry Ann Hernandez
    0

    Hey guys,

    I just used a class instead to access the control using jquery. I was just wondering why i'm not encountering same issue with my other control.

    Thanks though. :D

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Feb 03, 2011 @ 09:59
    Michael Latouche
    0

    Hi Sherry,

    Just for your information: if you want to access a server-side user control from client-side code, you can also use the "ClientID" property of your server side control. This will give you the actual ID of your control at the client side, depending of its parents etc. like Richard mentioned.

    Cheers,

    Michael.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Feb 03, 2011 @ 10:11
    Richard Soeteman
    0

    True but you still can't use it in an extenal Javascript file using JQuery. @Sherry, Could be a lot of things causing that. But by default Asp.Net is generating id's for you so better to use Classes instead of id's to ensure you don't run into issues.

    Cheers,

    Richard

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 03, 2011 @ 10:19
    Jan Skovgaard
    0

    Hi Richard and Sherry

    @Richard: In ASP.NET 4 it should be possible to generate a clean id for the HTML, right? I just can't seem to remember the setting at the moment.

    But if one is using 3.5 then classes are the way forward.

    Just a thought.

    Cheers

    /Jan

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Feb 03, 2011 @ 10:26
    Richard Soeteman
    0

    @Jan,

    Yes true, but not everyone is using 4.0

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Feb 03, 2011 @ 10:28
    Michael Latouche
    1

    Hi,

    In Asp.Net 4 I think you can use the ClientIDMode property to specify how the client ID must be generated. Using the "static" value uses the value of the ID attribute: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

    Cheers,

    Michael.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 03, 2011 @ 10:37
    Jan Skovgaard
    0

    Hi

    @Richard, true - but just thought it's worth mentioning for future reference if others have a look at this post if they have the same issue :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft