简体   繁体   English

升级到Sitecore 7.2后未触发按钮单击事件

[英]Button click event not fired after upgrading to Sitecore 7.2

I have recently upgraded from Sitecore 6.5 to Sitecore 7.2. 我最近已从Sitecore 6.5升级到Sitecore 7.2。 I have worked through a number of issues, refactored search, etc. However, on pages other than the homepage my <asp:Button /> were not submitting the form due to __doPostback being undefined. 我已经解决了许多问题,重构搜索等问题。但是,由于主页__doPostback未定义,我的<asp:Button />不在主页上提交了表单。 To resolve this I added an <asp:ScriptManager /> to my layout and now the javascript fires on click and the form is submitted/reloaded. 为了解决这个问题,我在布局中添加了<asp:ScriptManager /> ,现在javascript在单击时触发,并且表单已提交/重新加载。

The problem I'm having now is that my server-side click event handler is not being fired for any buttons on that page. 我现在遇到的问题是该页面上的任何按钮都没有触发我的服务器端单击事件处理程序。

Below is my code: 下面是我的代码:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Login Page.ascx.cs"
    Inherits="MyProject.layouts.Login.Login_Page" %>

<asp:Button ID="TestButton" runat="server" OnClick="TestButton_OnClick" />

And my codebehind 而我的代码背后

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyProject.layouts.Login
{
    public partial class Login_Page : System.Web.UI.UserControl
    {        
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void TestButton_OnClick(object sender, EventArgs e)
        {
            throw new Exception("Clicked");
        }
    }
}

On click the event is never fired. 单击时,事件永远不会触发。 Any ideas out there? 有什么想法吗? I'm thinking it might be related to the same reason the pages didn't have __doPostback defined. 我认为这可能与页面未定义__doPostback的相同原因有关。

If you have caching enabled for your sublayout/rendering, then this is the expected behaviour since the rendered HTML is cached and your server side code will not be triggered after first load. 如果为子布局/渲染启用了缓存,则这是预期的行为,因为缓存了渲染的HTML,并且第一次加载后不会触发服务器端代码。 Meaning the Page_Load event will not be re-triggered neither will your Click event for your button. 这意味着不会重新触发Page_Load事件,也不会为按钮的Click事件触发。

The easiest way to check is if it is a caching issue is to clear the cache (via /sitecore/admin/cache.aspx) and see if your event is triggered. 最简单的检查方法是否是缓存问题是清除缓存(通过/sitecore/admin/cache.aspx),然后查看事件是否被触发。 You could also disable the cache in the element by setting cacheHtml="false" . 您还可以通过设置cacheHtml="false"来禁用元素中的缓存。 This will help you identify the caching issue, you should fix the underlying issue by disabling caching for that control. 这将帮助您确定缓存问题,应通过禁用该控件的缓存来解决根本问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM