转发器在创建项目时触发事件
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
或CodeProject:
http://www.codeproject.com/Articles/108887/Client-Ids-Generation-with-ASP-NET
但是如何从Repeater中捕获正确的ClientID以在JavaScript中使用它?
答案 0 :(得分:4)
使用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