简体   繁体   中英

Get ClientId of control in Repeater

The repeater fires the event when Item is created

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

And it is possible to catch and modify the control on this single data row.

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

Now the problem is, that for any JavaScript, it is needed to determine the correct client ID. But the control does not hold the Client ID, just the lblShipmentDetails String.

What MSDN says:

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

or CodeProject:

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

But how to catch the correct ClientID from Repeater to use it in JavaScript ?

ClientDi

Source is generated with auto-id. How to get this id? 自动ID

Use DataBound Event. To get the control ID, the repeater needs to bind data first. Then just ask for ID as in the Created event.

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM