ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID?

前端 未结 3 1572
逝去的感伤
逝去的感伤 2021-01-02 09:57

Okay, I\'m pretty confused about the IDs of dynamically created controls.

Public Class TestClass
    Inherits Panel
    Implements INamingContainer

    Func         


        
相关标签:
3条回答
  • 2021-01-02 10:08

    The ClientIDMode was added to ASP.NET 4 to allow control if you want it. It is particularly useful for client side libraries such as jQuery. ASP.NET's magic hinges on the uniqueness of controls. If you decided to use Static make sure they are unique, as you may face some unexpected runtime errors down the road.

    0 讨论(0)
  • 2021-01-02 10:10
    • The ID is the serverside ID that you use in your code.
    • The UniqueId corresponds to the "name" attribute of the generated HTML element.
    • The ClientID corresponds to the "id" attribute of the generated html element. So it depends which attribute you need (name is sent with form post, id is used for DOM manipulation).
    • Not sure what the uniqueclientid is :)

    ASP.Net 4 adds clientIdMode which allows you to force the id attribute to match the serverside id (and thus be more predictable) if you set it to "static".

    0 讨论(0)
  • 2021-01-02 10:14

    Use the ClientID property.

    ClientIDMode is there to support the ability to 100% set the actual ID used by the control..or not. Your choice. Basically it aids in writing javascript code.

    0 讨论(0)
提交回复
热议问题