ID VS的UniqueID VS客户端ID VS UniqueClientID VS StaticClientID? [英] ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID?

查看:135
本文介绍了ID VS的UniqueID VS客户端ID VS UniqueClientID VS StaticClientID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我是pretty的困惑动态创建的控件的ID。

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

Public Class TestClass
    Inherits Panel
    Implements INamingContainer

    Function TestClassInit() Handles Me.Init

        Dim pnlMainPanel As New Panel
        Me.Controls.Add(pnlMainPanel)

        Dim pnlTest1 As New Panel
        pnlMainPanel.Controls.Add(pnlTest1)

        pnlTest1.ClientIDMode = UI.ClientIDMode.Inherit ' DEFAULT
        'pnlTest1.ID = "ctl01"
        'pnlTest1.UniqueID = "ctl00$MainPanel$ctl01"
        'pnlTest1.ClientID = "MainPanel_ctl01"
        'pnlTest1.UniqueClientID = "ctl00_MainPanel_ctl01"
        'pnlTest1.StaticClientID = ""

        pnlTest1.ClientIDMode = UI.ClientIDMode.Predictable
        'pnlTest1.ClientID = "MainPanel_ctl01" (no change)

        pnlTest1.ClientIDMode = UI.ClientIDMode.AutoID
        'pnlTest1.ClientID = "ctl00_MainPanel_ctl01"

        pnlTest1.ClientIDMode = UI.ClientIDMode.Static
        'pnlTest1.ClientID = ""

    End Function
End Class

为什么5个不同的ID ??

Why the 5 different IDs??

当你应该使用不同的ID模式?

When should you use the different ID modes?

(我看过MSDN文档,但他们像往常一样,没有特别的启发。)

(I read the MSDN docs, but they were, as usual, not particularly illuminating.)

如果我不在乎的什么的ID是,只是想添加一个控制及;到动态添加AJAX扩展,模式/ ID组合,我应该用这给它的ID?

If I don't care what the ID is, and just want to add a control & give its ID to a dynamically added AJAX extender, which mode/ID combo should I use?

推荐答案

  • ID是你在code。使用服务器端的ID。
  • 的唯一ID对应生成的HTML元素的name属性。
  • 的客户端ID对应生成的HTML元素的id属性。所以,这取决于它的属性,你需要(名发送表单后,ID用于DOM操作)。
  • 不知道uniqueclientid是:)

ASP.Net 4增加的ClientIDMode它允许你强制id属性相匹配的服务器端ID(因此更predictable),如果你将其设置为静态。

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".

这篇关于ID VS的UniqueID VS客户端ID VS UniqueClientID VS StaticClientID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆