Clicking ImageButton Has No Effect

J

Jonathan Wood

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
 
E

Elroyskimms

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
 
J

Jonathan Wood

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
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top