【问题标题】:ASP.NET not calling code behind even in debugASP.NET 即使在调试中也不会调用代码
【发布时间】:2012-12-17 14:05:07
【问题描述】:

正如它所说,当我在调试中运行我的应用程序时,不会调用代码隐藏。

我一开始就有这个问题,并设法通过放弃我正在处理的页面并开始一个全新的页面来解决它。

不过现在这个好像也坏了!

基本上,它只是打开显示未更改的 HTML,而无需运行任何 C# 代码,也不会遇到任何断点。

它可以构建,但我还没有尝试部署它,因为我目前没有可用的服务器。

这是我在 index.aspx.cs 后面的代码:

namespace PAPS
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        { 
            string username = User.Identity.Name;
            // check security
            Security security = new Security(username);
            divUsername.InnerText = username;
            security = null;
        }
    }
}

index.aspx 中的页面声明如下:

<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="True" EnableViewState="false" CodeBehind="index.aspx.cs" Inherits="PAPS.index" %>

大家有什么有用的建议吗?

谢谢

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    你有

    AutoEventWireup = false
    

    除非您自己处理事件,否则请尝试将其设置为 true。

    【讨论】:

    • 我将使用 jQuery 来处理这些事件——我讨厌所有这些回发!这真的可能导致问题吗?我以前做过,没有问题...
    • @bukko 您可以将 jQuery 用于客户端事件,但如果您希望 Page_Init 和 Page_Load 在页面提供之前运行,请将其设置为 true。
    猜你喜欢
    • 1970-01-01
    • 2022-12-28
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2019-10-14
    • 1970-01-01
    • 2014-12-22
    相关资源
    最近更新 更多