.ascx user control button_click is not firing Sitefinity Custom Module - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

.ascx user control button_click is not firing Sitefinity Custom Module

  • .ascx user control button_click is not firing Sitefinity Custom Module
  • 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)
               
               
           
       

     

  • 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.
  • 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
  • Hi Josh, I have enabled the ViewState but still no difference
  • 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
  • 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
  • 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!
  • @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
  • 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!
  • @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?
  • 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? 
  • 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. 
  • @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


  • 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 :)