.ascx user control button_click is not firing Sitefinity Cus

Posted by Community Admin on 04-Aug-2018 12:23

.ascx user control button_click is not firing Sitefinity Custom Module

All Replies

Posted by Community Admin on 25-Apr-2012 00:00

I have come across this weird problem where my button click event is not firing. I have tried almost all the possiblities but still no luck. googling for couple of hours now but still no help. Some ppl experienced exactly the same problem on different forums but no specific answer. I tried the button_click event and also tried registring an event handler, none of them work. In my scenario I have a sitefinity5 custom module where I am showing employee information along with employee data. on employee picture click i am displaying a JQUERY dialog where i have this button. When application load, it fires the page_load of code behind file and also when i click on employee picture at first, it fires the page_load but dont fire button_click ever. Any subsequent click on picture dont even fire the Page_Load of code behind file. Anyone's help will really really be appreciated. Following is my code snippet.

    <%@ Control Language="C#" AutoEventWireup="true" Inherits="SitefinityWebApp.SfCtrlPresentation.OpenAccessDataProvider_a4a794260c0b4440b466f75d11146db8" Codebehind="OpenAccessDataProvider,a4a794260c0b4440b466f75d11146db8.ascx.cs" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%--<%@ Register TagPrefix="jq" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" %>--%>
   
    <telerik:RadListView ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
            <ul class="sfitemsList sfitemsListTitleDateTmb">
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </ul>
        </LayoutTemplate>
   
            <ItemTemplate>
          <li class="sfitem sfClearfix">
                <h2 class="sfitemTitle">
                    <sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" />
                </h2>
               <sf:AssetsField ID="AssetsField1" runat="server" DataFieldName="Picture" />
               <sf:SitefinityLabel ID="SitefinityLabel1" runat="server" Text='<%# Eval("Designation")%>'  WrapperTagName="div" HideIfNoText="true" CssClass="sfitemShortTxt" />          
              <sf:SitefinityLabel ID="SitefinityLabel2" runat="server" Text='<%# Eval("CompanyName")%>' WrapperTagName="div" HideIfNoText="true" CssClass="sfitemShortTxt" />
              <sf:AssetsField ID="AssetsField2" runat="server" DataFieldName="Documents"/>
          </li>
        </ItemTemplate>
    </telerik:RadListView>

    <sf:Pager id="pager" runat="server"></sf:Pager>
   
    <sf:ResourceLinks ID="resourcesLinks" runat="server">
        <sf:ResourceFile JavaScriptLibrary="JQuery" />
    </sf:ResourceLinks>

    <div class="dialogTest"> <br />
    <br />
    Please enter your email address: <input type="text" name="emailAddress" style="width: 300px;" /><br />
    <br />
   
    <asp:TextBox ID="txtBox" runat="server"></asp:TextBox> <br/>
    <asp:LinkButton Runat="server" ID="btnSubmit" Text="Submit" /> <br/>
    <asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="False"
            onclick="Button1_Click" />
    </div>
   
    <script type="text/javascript">
    $j = jQuery.noConflict();
    $j(document).ready(function ()
        $j(".sfClearfix .sfimageWrp img").click(function ()
            $j(".dialogTest").addClass("open");
            //return $j(this).attr("src");
        );
    );
    </script>
    
    //.cs file
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace SitefinityWebApp.SfCtrlPresentation
   
        public partial class OpenAccessDataProvider_a4a794260c0b4440b466f75d11146db8 : System.Web.UI.UserControl
            
            protected void Page_Load(object sender, EventArgs e)
           
                if (IsPostBack)
               
                    btnSubmit.Click+= new EventHandler(btnSubmit_Click);
               
           
            protected void btnSubmit_Click(object sender, EventArgs e)
             
           
            protected void Button1_Click(object sender, EventArgs e)
           
           
       
   

 

Posted by Community Admin on 25-Apr-2012 00:00

Hi Waseem, by default pages in the Sitefinity frontend have Viewstate disabled to help performance. this is likely the cause for the postback event not firing.

to enable it, just open the page properties (under the Actions menu on the page list in admin) and check the box to enable viewstate

hope this is helpful, let me know if I have misunderstood your question.

Posted by Community Admin on 25-Apr-2012 00:00

Hello Waseem,

Try to wire up your event in the Page_Init event, not in Load.

protected void Page_Init(object sender, EventArgs e)
  
    // wire button event here
  


Greetings,
Dimitar Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 26-Apr-2012 00:00

Hi Josh, I have enabled the ViewState but still no difference

Posted by Community Admin on 26-Apr-2012 00:00

Hi Dimitar Dimitrov, Really glad to see a reply from Telerik! and hope my problem will now get sorted soon. I tried registering my EventHandler in Page_Init but still no difference. Also, Page_Load and Page_Init only hit when i click the button first time. On any subsequent clicks it even dont fire Page_Init or Page_Load. Any other advice? Really appreciate your help!
Regards

Posted by Community Admin on 01-May-2012 00:00

Hi Waseem,

Is it possible to attach your custom module project as an archive, so I can take a look at it and hopefully tell you what is the problem?

Kind regards,

Dimitar Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-May-2012 00:00

Hi Dimitar,
it don't allow me to add my archived project as it accept only .jpg, jpeg, gif and png extensions. Is there any other way around to upload my project? Thanks!
Regards!

Posted by Community Admin on 01-May-2012 00:00

@Waseem, I had a ticket pending on this exact issue a month ago...they couldnt get it to work :/. Big bug IMO...In my case it was click s button to download a pdf...so I was able to sneak around it with an ashx handler...hacky though

Posted by Community Admin on 01-May-2012 00:00

Hi Steve,
Thanks for your reply! is there any chance if you can share your code example? Initially, I thought I may be doing something terribly wrong but now as you also have come across more or less the same situation, I would really like to see the code example. Also, currently my issue is being looked by Telerik Team. I hope they will come up with some good work around.
Regards!

Posted by Community Admin on 01-May-2012 00:00

@Waseem,  well the code is not needed, and I dont know if it'd even work for your scenario...you just add a new .ashx file to your solution, then in my template I made an <a> tag point to it and pass in values along the querystring...I'm not sure what you're needing to do but that would work if it's to "download a file", otherwise would an $.ajax or RadXmlHttpPanel work so it's an asyc clientside click?

Posted by Community Admin on 02-May-2012 00:00

Hi Steve,
In my scenario, I am ultimately be downloading the file that is clicked but in-between that, I am populating a JQuery dialog where, I am taking input and validating the email regular expression. This Jquery dialog has a submit button and I only want to allow downloading once the dialog is submitted. Otherwise, on file click it opens the file directly and there is no issue with it.
The problem I have is to implement my own logic at button_click event in code behind file and also, I want to catch the textbox input (Email Address) for internal use but over here it doesn't even provide me the textbox value. It is really strange behaviour that I cant access any of the control in code behind file. I also have tried supplying textbox value from code behind at Page_Load that works fine and it display value in my control but dont work the other way around. It seems like the problem with page and module builder's user control life cycle? 

Posted by Community Admin on 09-May-2012 00:00

any luck with this? I'm having the same problem. Probably the only difference is that my linkbutton is inside a custom field control for a locations module. This control will assign multiple entries of hours of operation for a location. Each time I click the save button, linkbutton, the page fires a postback but not the server side event. 

Posted by Community Admin on 10-May-2012 00:00

@Ernest.. yes I have got a work around from Sitefinity team. It is not very much straight forward and involve injecting some logic. First, you need to find the "client side control ID" of your link button (Reqiest.Form.AllKeys). It must be the combination of something like 'ctl001$lnkbuttonid'. Once you catch this id in Page Post Back than you can throw your button click implementation.
Following is the code snippet.
<div class="dialogTest" visible="false"> <br /><br />
    Please enter your email address: <asp:TextBox CausesValidation="true" ID="txtEmailAddress" runat="server" style= "Width: 300px;" /> <br/>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
        ControlToValidate="txtEmailAddress" ErrorMessage="Email is required" />
    <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
        ControlToValidate= "txtEmailAddress"
        ErrorMessage="Please enter a valid email address!"
        ValidationExpression= "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]1,3\.[0-9]1,3\.[0-9]1,3\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]2,4|[0-9]1,3)(\]?)$"/> <br/>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true"/>
</div>
above in my user control I have an asp:Button i-e btnSubmit and in the code behind I am going through all the control Id's and catching the particular id which is ending with btnSubmit and code is as follow
            if (IsPostBack)
           
                GetbtnSubmitUserControlID();

                if (!string.IsNullOrEmpty(clientIdKey))
               
                    var emailAddress = Request[txtEmailAddress.UniqueID];
                    if (!string.IsNullOrEmpty(emailAddress))
                   

                   
               
           
        private string GetbtnSubmitUserControlID()
       
            var totalKeys = Request.Form.Count;
            if (totalKeys > 0)
           
                for (int indexOfButton = 0; indexOfButton < totalKeys; indexOfButton++)
               
                    var ctrlString = Request.Form.GetKey(indexOfButton).ToLower();
                    var found = ctrlString.LastIndexOf("btnsubmit");
                    if (found != -1)
                   
                        clientIdKey = Request.Form.Get(indexOfButton); // clientIdKey is a public level variable
                   
               
           
            return null;
       
I hope it will help you. Let me know if it doesn't work.
Regards


Posted by Community Admin on 04-Sep-2012 00:00

I typed up a response to this, but it didn't seem to post

I've hit this problem yet again, and I'd like Telerik to create a PITS on it.  It's absolutely insane to me that a webforms based webapp has problems with button clicks which are like "Hello World 101"

Please fix :)

Posted by Community Admin on 05-Nov-2012 00:00

*BUMP*

Hit this problem again... <asp:Button> inside a RadListView doesn't fire.

Sitefinity - please add solution to the next release 5.3 - or if this is simply impossible due to some internal code - please let us know!

Posted by Community Admin on 05-Nov-2012 00:00

I've all but given up with usercontrols...(if I need a postback).

Instead I use a thunder-generated SimpleView control.  I find I have significantly less issues with click events.

Posted by Community Admin on 06-Nov-2012 00:00

@Stephen

If I remember right, Buttons do not fire Click events inside ListViews.  Instead the fire the ListView's ItemCommand Event instead.  Putting a CommandName property on your button and checking that in the ListView's ItemCommand event should allow you to complete what you need.

Posted by Community Admin on 07-Dec-2012 00:00

i'll take it one further... for debugging i made a dummy.aspx page and dropped a UC in it i'm working on... zero postbacks from buttons/etc.

Posted by Community Admin on 14-May-2013 00:00

I've just spent 3 days debugging and hacking with session variables to get a multiple form user control working on a critical business process because in sf 4.4, the button click events stopped working.  The guy who wrote the widget in 2010/2011 put loads of stuff in the page load ispostback and loads controls onto the form....

I had to make a couple of simple changes to the widget and was astonished when the on click events weren't firing... I thought I had done some damage to the page, even though I couldn't imagine what I could have do to break them so badly.  I've spent 3 days redoing the logic on the page using session variables to try and work out where the user is in the page process...but its boiled down to the user click "accept" or "quote again" and I have to know which button was clicked.

I am going to see if i can get the above workaround going in my site urgently.

What's the word on this major bug, is it fixed in newer versions of SF?  

Posted by Community Admin on 14-May-2013 00:00

Do you have any code to share?  I am not implying that you are not having problems but I have never had an issue with buttons not firing unless they were dynamically generated or were located in some sort of template control like a Repeater.  When they were dynamically generated and it wasn't working, it is usually because they were not re-instantiated before the Page_Load Event.  If your buttons are in a control similar to a repeater, they won't fire a button click event but item command event.

If you can post code, maybe one us can give you a hint that will allow you to continue with your work.

Posted by Community Admin on 29-May-2013 00:00

Thanks for the help offer.

I reverted to the code base from september before i made changes and the upgrade, redid the 4.4 upgrade and the codes firing, so it may have been something i had changed which was stopping the event firing, or a combination of my changes and the upgrade.

The reverted version took me a few days in Beyondcompare to merge all my changes back in, and then i restarted the changes to the widget which was what i was trying to do in the first place.

There are still a few bits not working 100% or as intended, but the business is happy with the state of the system and I have had to move on due to other priorities.

Thanks for the offer of the help.  

Simon

Posted by Community Admin on 26-Sep-2013 00:00

Hello everyone.

I had a similar scenario to Steve in that I had a couple of Repeater's on my page, each rendering a list of Link buttons which would fire off an event to generate a PDF document. The link buttons had an OnCommand event which would handle the PDF generation but said event was not firing when I placed this within a Sitefinity user control.

What I did to solve this was to wrap an update panel around my content and then set a post back trigger for each repeater i.e.

<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
    <ContentTemplate>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="RepeaterList1" />
        <asp:PostBackTrigger ControlID="RepeaterList2" />
        <asp:PostBackTrigger ControlID="RepeaterList3" />
    </Triggers>
</asp:UpdatePanel>

In the Title and Properties of the page where you're dropping this user control, I set Enable ViewState to true and Include RadScriptManager to false. Sure enough, this got me into the OnCommand event and worked as I wanted.

I'm not sure if this works for a standard button click as I haven't had chance to try that myself but thought I would share my experience in case someone stumbles upon this issue. 

Posted by Community Admin on 05-Oct-2015 00:00

Hi,

I am using sitefinity 7.3. My button click event not fired but client side operation working fine such as validation  while I am change my page template or create same template as previous  assign to page then it is working properly  So please reply as soon as possible 
Thanks, 

Posted by Community Admin on 08-Oct-2015 00:00

Hello Vakeel,

I have just posted a reply in the following forum thread with a suggestion which you can try.  

Regards,
Sabrie Nedzhip
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed