onClick in aspImage???

G

Guest

Can someone please tell me how i execute an onClick event in an asp:Image tag!

I want to do the following!

Thanks!

<asp:Image runat="server" ID="ibtnExpandResource"
ImageUrl="../images/user.gif" onClick="Javascript: OnPlusClick(this);"
style="cursor:hand;"></asp:Image>
 
G

Guest

Should be able to do that from code.... take out the onclick from aspx and
add the following in your code-behind (this is in c#)

ibtnExpandResource.Attributes.Add("onclick", "javascript:OnPlusClick(this);");

HTH


Dan
 
B

Bob Barrows [MVP]

Tim::.. said:
Can someone please tell me how i execute an onClick event in an
asp:Image tag!

I want to do the following!

Thanks!

<asp:Image runat="server" ID="ibtnExpandResource"
ImageUrl="../images/user.gif" onClick="Javascript: OnPlusClick(this);"
style="cursor:hand;"></asp:Image>

In Page_Load, do this:
ibtnExpandResource.Attributes.Add("onclick","Javascript:
OnPlusClick(this);")

HTH,
Bob Barrows
 
G

Guest

The ASP:Image tag is in a templatecolumn within a datagrid!

I don't think this would work???

Any Ideas!

Thanks
 
E

Eliyahu Goldin

This looks fine. There is no need to use Attributes in code behind since
there is no server-side onclick event for Image control. What problem are
you experiencing?

Eliyahu
 
B

Bob Barrows [MVP]

Oh. I think you will need to do this in PreRender. Unless ... to Eliyahu's
point, shouldn't it work just by setting the attribute in the asp: tag? I
don't have time to test it myself right now, but did you test before
posting? If so, what happened?

Bob Barrows
 
B

Bob Barrows [MVP]

Ok, I found the time to test it (I was curious). This works fine:

<script type=text/javascript>
function test(obj)
{
alert(obj.parentElement.parentElement.rowIndex)
}
</script>
....
<asp:TemplateColumn>
<ItemTemplate>
<IMG src="../Images/Completed.gif" onclick="test(this)">
</ItemTemplate>
</asp:TemplateColumn>

Bob Barrows
 
B

Bob Barrows [MVP]

Heh. This isn't really testing what you were asking about (i just noticed).
Let me try again ... yes it still works:

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image id="Image1" runat="server"
ImageUrl="../Images/Completed.gif"
onclick="test(this)"></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>

The word "onclick" has the red squiggly underline, but it can safely be
ignored.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top