Clicking ImageButton Has No Effect

Discussion in 'ASP .Net' started by Jonathan Wood, Oct 5, 2007.

  1. 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
    Jonathan Wood, Oct 5, 2007
    #1
    1. Advertising

  2. Jonathan Wood

    Elroyskimms Guest

    On Oct 5, 2:13 pm, "Jonathan Wood" <> 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
    Elroyskimms, Oct 6, 2007
    #2
    1. Advertising

  3. 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
    Jonathan Wood, Oct 6, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWljaGFlbCBFdmFuY2hpaw==?=

    Warning page has expired when clicking back

    =?Utf-8?B?TWljaGFlbCBFdmFuY2hpaw==?=, Apr 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    595
    =?Utf-8?B?TWljaGFlbCBFdmFuY2hpaw==?=
    Apr 20, 2004
  2. tshad
    Replies:
    3
    Views:
    5,327
    Lau Lei Cheong
    Oct 27, 2004
  3. Bendik Engebretsen

    Mouseover effect on imagebutton

    Bendik Engebretsen, Aug 3, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    22,398
    shadowzz
    Sep 2, 2010
  4. Dariusz Tomon
    Replies:
    2
    Views:
    861
  5. Replies:
    1
    Views:
    309
Loading...

Share This Page