Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brock Ciochetti 2 posts 22 karma points
    Feb 05, 2010 @ 17:55
    Brock Ciochetti
    0

    Page_Load and _Click events not firing in user control

    We are transitioning our website to Umbraco, so right now we are playing around with using .Net user controls to add some business specific functionality. Right now I have a very basic user control:

    TestControl.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="UmbracoUserControls.TestControl" %>
    <asp:Panel ID="Questions" runat="server">

    <asp:Button ID="btn_Calculate" Text="Recommendations" runat="server" onclick="btn_Calculate_Click" ></asp:Button>

    </asp:Panel>
    <asp:Panel ID="Answer" runat="server">
    Your recommendation is: <asp:Label ID="lbl_Message" runat="server"></asp:Label>
    </asp:Panel>

    TestControl.ascx.cs

    namespace UmbracoUserControls
    {
        public partial class TestControl : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                lbl_Message.Text = "Message";
            }
            protected void btn_Calculate_Click(object sender, EventArgs e)
            {
                lbl_Message.Text = "Message";
            }
        }
    }

    I've uploaded the .ascx to the usercontrol directory, UmbracoUserControls.dll to the bin directory, created the macro that points to the usercontrol. I used the macro button to add the Macro into a RichTextEditor on one of our pages. The content from the user control displays properly, but neither the Page_Load or the btn_Calculate_Click events fire. I've noticed one other thread on the forum describing similar issues, but it stopped before a resolution was posted. http://our.umbraco.org/forum/core/general/5341-Net-user-control-button-click-events-not-working

    Any guidance would be greatly appreciated as I'm kinda scratching my head right now.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Feb 05, 2010 @ 18:34
    Morten Bock
    1

    This is a longshot, but I saw this in a site where there was an asp:LinkButton in another control on the site. The linkbutton cause the form to render differently because it needed the postback javascript. When I removed the linkbutton, the events started working again.

    Another thing that might be wrong is if you are rendering your RTE text through an xslt macro? This will actually render the ascx file as you describe, but not register it as a control.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Feb 05, 2010 @ 18:36
    Stefan Kip
    0

    Did you try to include the usercontrol in a template with the ASP.NET way of using usercontrols? I mean with the <%@ Register %> directive?

  • Brock Ciochetti 2 posts 22 karma points
    Feb 05, 2010 @ 18:49
    Brock Ciochetti
    0

    Thanks for your help guys. The company we had develop the initial site has a weird way of handling pages with user controls, so they actually have a different template needed for those pages.

  • tarekahf 215 posts 153 karma points
    May 03, 2010 @ 21:58
    tarekahf
    0

    I faced similar problem. See this http://bit.ly/bPfxG8 for complete details. The link button if used under Umbraco will case ASP.NET event model to misbehave.

    Tarek.

Please Sign in or register to post replies

Write your reply to:

Draft