Question Including eval / bind values in OnClientClick code

ebtihal

Member
Joined
Mar 14, 2011
Messages
21
Programming Experience
Beginner
hi ..
I need to open a popup window to display an image from a ListView (VS 2008).
What I am trying to do is in asp:ImageButton control, like this:


<asp:ImageButton ID="ImageButton1" runat="server" Height="150px"
ImageUrl= '<%# Bind("image_url") %>' Width="150px" ImageAlign = "Middle"

OnClientClick= '<%# string.Format("window.open('popup.aspx?{0}')", Eval("image_id")) %>'
/>

But i got that error :
The server tag is not well formed.

any help plz !

 
Do not use inline code. Rather use the code-behind.

    Protected Sub ListView1_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
        Dim theitem As ListViewDataItem = e.Item
        Dim imageid As String = DataBinder.Eval(theitem.DataItem, "image_id").ToString
        Dim jscode As String = String.Format("window.open('popup.aspx?{0}')", imageid)
        Dim theimage As Image = CType(e.Item.FindControl("ImageButton1"), Image)
        theimage.Attributes.Add("onclick", jscode)
    End Sub
 
Back
Top