How to open a popup window on button click of datalist control in asp.net

Hello All,

 I have Datalist controll which contains Details of the product like name, discription, price, image of the product, Add to cart button and [B]"Zoom"[/B] etc. Now on click of this "zoom" i want to open a pop up window showing Image of the product.

I tried
Dim lkb_zoom As New System.Web.UI.WebControls.ImageButton
lkb_zoom = dtListDetail.FindControl(“imgbtn_Zoom”)
lkb_zoom.Attributes.Add(“onclick”, “popWin()”)

on both events,on page load and on ItemCommand of datalist but nothing is comming in the lkb_zoom
and no popup window getting error
“Object reference not set to an instance of an object.”

Please kindly provide me the Solution as soon as possible

Thanks in advanced

You need to add the attribute during the DataList’s ItemDataBound event.


Sub Item_Bound(sender As Object, e As DataListItemEventArgs)

         If e.Item.ItemType = ListItemType.Item Or _
             e.Item.ItemType = ListItemType.AlternatingItem Then

            Dim ImageButton As imgBtn = _
                 CType(e.Item.FindControl("imgbtn_Zoom"), ImageButton)

            imgBtn.Attributes.Add("onclick", "popWin()")

End If

I also assume you’re going to want to pass in a url or image src to popWin to show the correct image for each item.

Yah i want to pass the url of the image also
But still popup window is not comming

Try looking at this guy’s examples. I have used them quite a bit lately.

http://mattberseth.com/blog/modalpopupextender/