PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 2.33 average.

Clicking ImageButton Has No Effect

 
 
Jonathan Wood
Guest
Posts: n/a
 
      5th Oct 2007
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

 
Reply With Quote
 
 
 
 
Elroyskimms
Guest
Posts: n/a
 
      6th Oct 2007
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

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      6th Oct 2007
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/forum...t-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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
imagebutton clicking issues vortigern79@yahoo.com Microsoft ASP .NET 1 4th Aug 2007 01:22 PM
mouseover effect on asp:imagebutton - is it possible Dariusz Tomon Microsoft ASP .NET 2 20th Feb 2006 05:05 AM
Mouseover effect on imagebutton Bendik Engebretsen Microsoft ASP .NET 2 3rd Aug 2005 03:40 PM
MM2 crashes when clicking on Transition or Effect icon daveg Windows XP Video 1 2nd Oct 2003 01:25 AM
I don't want to post a form by clicking on ImageButton =?iso-8859-1?Q?Ga=EBtan?= Microsoft Dot NET 1 27th Aug 2003 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.