Solved

Button click event not firing in UserControl

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now