Welcome Guest Search | Active Topics | Members | Log In | Register

Clicking ImageButton Has No Effect Options · View
Jonathan Wood
Posted: Friday, October 05, 2007 6:13:37 AM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 05/10/2007 06:13:37
Date: Fri, 5 Oct 2007 12:13:37 -0600

I'm trying to convert some old HTML pages to ASP.NET.

I'm experimenting with code that responds to a button click. But although
the mouse turns into a hand pointer when it is over the button, absolutely
nothing happens when I click it.

Does anyone know if this could have anything to do the fact that my button
is on a master page (along with the handler)? That shouldn't make any
difference should it?

My button looks like this:

<p>&nbsp;</p>
<asp:ImageButton runat="server" id="imgAddToCart"
ImageUrl="../images/addtocart.gif" OnClick="imgAddToCart_Click" />
<p>&nbsp;</p>

And at the top of the same master page, I have something like this:

<script runat="server">
protected void imgAddToCart_Click(object sender, ImageClickEventArgs e)
{
// Test code using HttpWebRequest here
}
</script>

Unfortunately, my project will not currently run in Visual Studio due to
some of the older constructs in the HTML code so I can't set breakpoints.
I'm just running it under Expression Web. But shouldn't the page refresh
after the postback or something? I get nothing.

Any tips appreciated.

Jonathan

Elroyskimms
Posted: Friday, October 05, 2007 10:22:36 AM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 05/10/2007 10:22:36
Date: Fri, 05 Oct 2007 17:22:36 -0700

On Oct 5, 2:13 pm, "Jonathan Wood" <jw...@softcircuits.com> wrote:
> I'm trying to convert some old HTML pages to ASP.NET.
>
> I'm experimenting with code that responds to a button click. But although
> the mouse turns into a hand pointer when it is over the button, absolutely
> nothing happens when I click it.
>
> Does anyone know if this could have anything to do the fact that my button
> is on a master page (along with the handler)? That shouldn't make any
> difference should it?
>
> My button looks like this:
>
> <p>&nbsp;</p>
> <asp:ImageButton runat="server" id="imgAddToCart"
> ImageUrl="../images/addtocart.gif" OnClick="imgAddToCart_Click" />
> <p>&nbsp;</p>
>
> And at the top of the same master page, I have something like this:
>
> <script runat="server">
> protected void imgAddToCart_Click(object sender, ImageClickEventArgs e)
> {
> // Test code using HttpWebRequest here
> }
> </script>
>
> Unfortunately, my project will not currently run in Visual Studio due to
> some of the older constructs in the HTML code so I can't set breakpoints.
> I'm just running it under Expression Web. But shouldn't the page refresh
> after the postback or something? I get nothing.
>
> Any tips appreciated.
>
> Jonathan

At first glance, it looks like your imgAddToCart_Click method is not
bound to the click event of the button. In VB.net, you would declare
the method:

protected sub imgAddToCart_Click(object sender, ImageClickEventArgs e)
handles imgAddToCart.Click

Notice the _handles imgAddToCart.Click_ after the method declaration.

I use the OnClick HTML attribute when I want the button to call some
client-side Javascript before firing the server-side Click event.

HTH,

-A

Jonathan Wood
Posted: Friday, October 05, 2007 1:20:27 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 05/10/2007 13:20:27
Date: Fri, 5 Oct 2007 19:20:27 -0600

Elroyskimms,

> At first glance, it looks like your imgAddToCart_Click method is not
> bound to the click event of the button. In VB.net, you would declare
> the method:
>
> protected sub imgAddToCart_Click(object sender, ImageClickEventArgs e)
> handles imgAddToCart.Click
>
> Notice the _handles imgAddToCart.Click_ after the method declaration.
>
> I use the OnClick HTML attribute when I want the button to call some
> client-side Javascript before firing the server-side Click event.

If I'm not mistaken, server-side controls use the OnClientClick property to
specify javascript.

According to
http://www.velocityreviews.com/forums/t367616-using-quothandlesquot-vb-vs-c.html,
C# doesn't have anything like Handles. But I did find discussions about
AutoEventWireup, which seems to be related.

Unfortunately, I was unable to find clear documentation on AutoEventWireup
and how it applies to a master page, and I found conflicting information
about its default value. I tried AutoEventWireup="true", both in my Master
directive and also in the DOCTYPE tag. Neither seems to have any effect.

Thanks.

Jonathan

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.1 (NET v2.0) - 9/10/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.050 seconds.