Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? Auto Id

like image 347
Nasenbaer Avatar asked Feb 20 '15 16:02

Nasenbaer


1 Answers

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
like image 102
Nasenbaer Avatar answered Oct 02 '22 06:10

Nasenbaer