【问题标题】:Get ClientId of control in Repeater在Repeater中获取控件的ClientId
【发布时间】:2015-04-22 10:03:17
【问题描述】:

中继器在创建项目时触发事件

 Protected Sub Repeater1_ItemCreated(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemCreated

并且可以捕获和修改这个单一数据行上的控件。

Dim lnk As HyperLink = CType(e.Item.FindControl("lblShipmentDetails"), HyperLink)

现在的问题是,对于任何 JavaScript,都需要确定正确的客户端 ID。但该控件不保存客户端 ID,只保存 lblShipmentDetails 字符串。

MSDN 是怎么说的:

https://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode%28v=vs.110%29.aspx

https://msdn.microsoft.com/en-us/library/1d04y8ss%28v=vs.140%29.aspx

或代码项目:

http://www.codeproject.com/Articles/108887/Client-Ids-Generation-with-ASP-NET

但是如何从 Repeater 中获取正确的 ClientID 以在 JavaScript 中使用它呢?

源是使用自动 ID 生成的。如何获得这个id?

【问题讨论】:

    标签: javascript html asp.net


    【解决方案1】:

    使用DataBound 事件。中继器要获取控件ID,需要先绑定数据。然后只需在 Created 事件中询问 ID。

        Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim btn As Button = CType(e.Item.FindControl("btnOrderTrackingConfirmMove"), Button)
            If btn IsNot Nothing Then
                Dim RealId As String = btn.Page.ClientScript.GetPostBackEventReference(btn, String.Empty).ToString
    
            End If
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      相关资源
      最近更新 更多