Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Clicking ImageButton Has No Effect

Reply
Thread Tools

Clicking ImageButton Has No Effect

 
 
Jonathan Wood
Guest
Posts: n/a
 
      10-05-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
 
      10-06-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
 
      10-06-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

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
Mouseover effect on imagebutton Bendik Engebretsen ASP .Net 3 09-02-2010 07:11 AM
imagebutton clicking issues vortigern79@yahoo.com ASP .Net 1 08-04-2007 12:22 PM
mouseover effect on asp:imagebutton - is it possible Dariusz Tomon ASP .Net 2 02-20-2006 05:05 AM
ImageButton has not onClick method tshad ASP .Net 3 10-27-2004 01:41 AM
I want to be able to access the internet by opening my browser and not right clicking and then clicking connect. James Johnson Computer Support 1 05-15-2004 03:40 AM



Advertisments