+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / OnClick Event is never fired on external temlate

OnClick Event is never fired on external temlate

8 posts, 0 answered
  1. Alistair
    Alistair avatar
    2 posts
    Registered:
    29 Jul 2012
    17 Jun 2010
    Link to this post
    Hello,

    I defined a event view template by Telerik.Sitefinity.Configuration.ControlsConfig.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <controlsConfig>
      <viewMap>
         <viewSettings hostType="Telerik.Events.WebControls.EventsView">
           <additionalTemplates>
                    <!--Single Item-->
           <add key="SingleItemTemplate" layoutTemplatePath="~/Templates/EventView.ascx" />
           </additionalTemplates>
         </viewSettings>
      </viewMap>
    </controlsConfig>

    The template works fine for the event, then I added a asp button on the template, and its event handler at the code behind.
     The problem is when I click the button, the OnClick event is never fired.
    Can anyone help me with this?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    18 Jun 2010
    Link to this post
    Hi Alistair,

    Could you try subscribing to button events like this:
    <script type="text/C#" runat="server">
        protected void Page_Load()
        {
            button1.Click += new EventHandler(button1_Click);
        }
     
        void button1_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
        </script>

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Alistair
    Alistair avatar
    2 posts
    Registered:
    29 Jul 2012
    21 Jun 2010
    Link to this post
    Hello,

    I tried your method, but it's not working.
    I submitted a support ticket for this and attached my template file.
    Can you please have a look at it?
    Ticket ID is : 320564

    Al
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Jun 2010
    Link to this post
    Hello Alistair,

    We will take a look at the support request you have opened and get back to you.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    01 Mar 2011
    Link to this post
    Guys I really need some help.

    I have tested this User Control outside Sitefinity 4.0.1160 and my btnBack works just fine. As soon as I add it to Sitefinity and drop it on the page, the btnBack_Click never gets hit.

    Can't work out what is going. My code is below.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BackButton.ascx.cs" Inherits="WebApplication3.BackButton" %>
     
    <asp:Button ID="btnBack" runat="server" Text="<< Back"
        onclick="btnBack_Click" />

    using System;
    using System.Web;
    using System.Web.UI;
     
    namespace WebApplication3
    {
        public partial class BackButton : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //get the referrer.
                if (!this.IsDesignMode() && !this.IsBackend() && !this.IsPreviewMode())
                {
                    HttpCookieCollection myCookies;
                    HttpCookie myCookie;
     
                    myCookies = Request.Cookies;
                    myCookie = myCookies["BackButton"];
     
                    // Read the cookie information and display it.
                    if (myCookie != null)
                    {
                        if (!string.IsNullOrEmpty(myCookie.Value))
                        {
                            //assign the post back url
                            this.btnBack.PostBackUrl = myCookie.Value;
                        }
                        else
                        {
                            // Reassign the new referrer
                            Response.Cookies["BackButton"].Value = Request.UrlReferrer.ToString();
     
                            //assign the post back url
                            this.btnBack.PostBackUrl = Request.UrlReferrer.ToString();
                        }
                    }
                    else
                    {
                        HttpCookie theCookie = new HttpCookie("BackButton");
                        theCookie.Value = Request.UrlReferrer.ToString();
                        theCookie.Expires = DateTime.Now.AddYears(999);
                        Response.Cookies.Add(theCookie);
                        this.btnBack.PostBackUrl = Request.UrlReferrer.ToString();
                    }
                }
     
                //assign the extra attributes.
                this.btnBack.Text = _text;
                this.btnBack.CssClass = _cssClass;
            }
     
            private string _text = "<< Back";
            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }
     
            private string _cssClass = "btnSilverBg50";
            public string CssClass
            {
                get { return _cssClass; }
                set { _cssClass = value; }
            }
     
            protected void btnBack_Click(object sender, EventArgs e)
            {
                Response.Cookies["BackButton"].Value = "";
            }
        }
    }


    Many thanks,
    Andrei
  6. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    03 Mar 2011
    Link to this post
    Anything from anyone?
    Thanks
  7. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Mar 2011
    Link to this post
    Hi Andrei,

    Can you try wiring this event from the code instead from template.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  8. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    08 Mar 2011
    Link to this post
    Radoslav,

    Thanks for looking at this issue. The problem is me assigning the PostBackUrl to the button. Once it is assigned it will not do a post back to it's self but take you to the PostBackUrl location. Hence, the Click event is never run. Now I do not assign PostBackUrl to the button but am doing Server Response.Redirects(Url) inside the Click event instead.

    It seems to work. I still however wonder how it was working outside Sitefinity and not when attached to the Sitefinity project. Ivan is sure that it is a Microsoft issue. Based on the behaviour I was observing I was unsure, but it is working now and I am putting the matter to bed.

    Many thanks for all your help,
    Andrei

Register for webinar
8 posts, 0 answered