Solved

Button click event not firing in UserControl

Posted on 2013-12-10
4
2,771 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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