Solved

Button click event not firing in UserControl

Posted on 2013-12-10
4
2,895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

689 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