Solved

Button click event not firing in UserControl

Posted on 2013-12-10
4
2,805 Views
Last Modified: 2013-12-17
Hi

I have a UserControl which looks like this:

UserControl.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucBasket.ascx.cs" Inherits="v2Shop.tarp.udv.UserControls.ucBasket" %>
<asp:UpdatePanel ID="upBasketLink" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <a class="hover-link"><asp:Image ID="imgBasket" runat="server" ImageUrl="~/images/design/kurv_30x30.png" /><asp:Label ID="nt_lbl_lblBasketQuantity" runat="server"></asp:Label></a>
    </ContentTemplate>
</asp:UpdatePanel>
<div class="sub">
    <asp:Label ID="lbl_lblBasketHeadline" runat="server"></asp:Label>
    <asp:UpdatePanel ID="upBasket" runat="server" UpdateMode="Conditional" >
        <ContentTemplate>
            <asp:GridView ID="gwBasket" runat="server"   
            AutoGenerateColumns="false" Width="500px" 
            AlternatingRowStyle-CssClass="Alt" CssClass="GridView" 
            ShowFooter="True" OnRowDataBound="gwBasket_RowDataBound" > 
            <HeaderStyle CssClass="GridHeader" />
            <FooterStyle CssClass="FooterStyle" />
            <AlternatingRowStyle CssClass="Alt"></AlternatingRowStyle>
            <Columns>
                  //Some cloumns
            </Columns>
          </asp:GridView>          
        </ContentTemplate>
      </asp:UpdatePanel>
      <asp:Button ID="btn_btnViewBasketBeforeShipping" runat="server" OnClick="btn_btnViewBasketBeforeShipping_Click" />
      <asp:Button ID="btn_btnCheckOut" runat="server" OnClick="btn_btnCheckOut_Click" />
    </div>

Open in new window

The code behind looks like this

UserControl.ascx.cs:
public partial class ucBasket : System.Web.UI.UserControl
  {
    double TotalBasketPrice = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        FillgwBasket();
      }
    }

    protected void btn_btnCheckOut_Click(object sender, EventArgs e)
    {
      Response.Redirect("CheckOutShipping.aspx");
    }

    protected void btn_btnViewBasketBeforeShipping_Click(object sender, EventArgs e)
    {
      Response.Redirect("CheckOut.aspx");
    }
}

Open in new window


My problem is that the click events for the two buttons does not fire.

I have tried several solutions I found on the internet, but I can't get any of them to work. I don't know if I'm doing it wrong, or they weren't solutions to my problem.

Does anyone have any suggestions how to make the two buttons click event fire?

If more information or code is need, just ask.

Regards
Søren Augustesen
0
Comment
Question by:poultarp
  • 3
4 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 39711073
Hi
Try below steps:


1. Delete click event for button
2. Comment out:

<asp:UpdatePanel ID="upBasketLink" runat="server" UpdateMode="Conditional">
    <ContentTemplate>

and

 </ContentTemplate>
</asp:UpdatePanel>

3. Go to Design mode

4. Double click on button to generate click event.

5. Save all

6. Go to Source mode and uncomment update panel which we comment in step 2.

7. Save all and Run application.
0
 
LVL 1

Author Comment

by:poultarp
ID: 39711220
Hi mroonal

Thank you for your tip. Unfortunately that did not solve the problem. The click events are still not fired.

Regards
Søren
0
 
LVL 1

Accepted Solution

by:
poultarp earned 0 total points
ID: 39713966
Hi

I manage to find a solution - at least for what I need the buttons to do.

All the two buttons did were redirect the user to another page, so instead of using

<asp:Button>

and Response.Redirect in the on click event, I changed the buttons to

<input type="button">

and in the onclick event i put

"location.href='NewPage.aspx'".

This didn't solve the issue with the click event not being fired, but it works for my needs.

Regards
Søren Augustesen
0
 
LVL 1

Author Closing Comment

by:poultarp
ID: 39723468
While this did not solve the "Click Event does not fire" issue, it did do what was needed in my case, redirecting the user to another page.

I guess this method could also be use with more advanced JavaScript in the "onclick" event of the "<input type="button">".
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question