Question

I am trying to wire some fancy Javascript (PopBox) to an ImageButton control and I am getting a very strange run-time (Compilation) error.

<asp:imagebutton id="imgBtnPicture" runat="server" 
      class="PopBoxImageSmall"
      pbshowcaption="true"
      title="Click to magnify/shrink"
      onclick="Pop(this,50,'PopBoxImageLarge');"
      width="90%">
  </asp:imagebutton>

I've looked at replacing the ImageButton web control with a simpler HTML img tag (which is what the PopBox documentation suggests).

Yet, I don't know how to populate an <img> tag from the CodeBehind file. Here is a typical statement which sets the .SRC property from an ASP.Net dataset row:

    Me.imgBtnPicture.Src = theRow.Item("ImageURL")

I've tried this as an alternative:

<img alt="" src="" 
   id="imgPicture" runat="server"class="PopBoxImageSmall" title="Click to magnify/shrink"        
   onclick="Pop(this,50,'PopBoxImageLarge');" width="90%"
/>

Visual Studio 2008 does not complain about this declaration above but in the codebehind file, how would I address this so I could populate the .Src attribute.

Intellisense, cannot even "see" this

 Me.imgPicture.src = theUrl    'this won't compile...

I added this at the top of the codebehind but seemed to have no effect:

Imports System.Web.UI.HtmlControls
Was it helpful?

Solution

the <asp:imagebutton onclick="..." > is for a server method (code behide).

try with onclientclick

OTHER TIPS

in asp.net imagebutton there is no property class change it to cssclass="PopBoxImageSmall"

then it will work.

It's case sensitive, make sure you're still setting the Src property, capital S...and just remove the src="" from the tag itself so there's no confusion by anyone reading it later:

Me.imgPicture.Src = theUrl
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top