Solved

Button click event not firing in UserControl

Posted on 2013-12-10
4
2,653 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now