简体   繁体   English

ASP.NET - 未调用隐藏代码 (C#) - AutoEventWireup 设置为 True

[英]ASP.NET - Code behind (C#) not being called - AutoEventWireup is set to True

I was working on an ASP.NET page and the code behind was executing properly.我正在处理一个 ASP.NET 页面,后面的代码正在正确执行。 I did more work on it and tried running it a few hours later, and the code stopped executing.我做了更多的工作,几个小时后尝试运行它,代码停止执行。 I don't understand why it's no longer running the C# code.我不明白为什么它不再运行 C# 代码。 The more common code behind problems that I could find on Google/Stack Overflow pointed at the AutoEventWireup being set to false or missing the runat server, but that doesn't seem to be true in my case?我可以在 Google/Stack Overflow 上找到的问题背后更常见的代码指出 AutoEventWireup 被设置为 false 或缺少 runat 服务器,但在我的情况下似乎并非如此? I have a feeling it's a minor mistake, but I can't seem to find it.我有一种感觉,这是一个小错误,但我似乎无法找到它。

Here's the code in the ASP page:这是ASP页面中的代码:

<%@ Page Title="Test Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WritebackModel.WritebackModel" Runat="server"%>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">

        function setText()
        {
            <%if (successfulWriteback) {%>
                document.getElementById('resultTitle').innerHTML = "Success!";
                document.getElementById('resultBody').innerHTML = "An exception was successfully added!";
            <%} else { %>
                document.getElementById('resultTitle').innerHTML = "Invalid Permissions";
                document.getElementById('resultBody').innerHTML = "Please contact your payroll rep to add a missing work record exception.";
            <%}%>
            <%Console.WriteLine($"Writeback: {successfulWriteback}");%>
        }

        function countdown()
        {
            var countdownTime = document.getElementById('counter');

            countdownTime.innerHTML = parseInt(countdownTime.innerHTML) - 1;

            if (parseInt(countdownTime.innerHTML) <= 0)
            { 
                window.close();
            }
        }

        function manualClose()
        {
            window.close();
        }

        setInterval(function () { countdown(); }, 1000);

        window.onload = setText;

    </script>

    <div class="jumbotron">
        <h1><span id="resultTitle" style="color:#6a67a7;"> </span></h1>
        <p class="lead" style="color:#a3a1c8;"> <span id="resultBody"> </span></p>
        <p class="lead">This window will close automatically within <span id="counter" style="background-color: #694e7b; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">120</span> second(s).</p>
        <p><a onclick="manualClose()" class="btn btn-primary btn-lg">Close now</a></p>
    </div>

</asp:Content>

This is what's in Site.Master.cs:这是 Site.Master.cs 中的内容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WritebackModel
{
    public partial class SiteMaster : MasterPage
    {
        protected static void Page_Load(object sender, EventArgs e)
        {
            WritebackModel.Page_Load(sender, e);
            Debug.WriteLine("Called WritebackModel.Page_Load");
        }
    }
}

and this is what's in Default.aspx.cs这就是 Default.aspx.cs 中的内容

namespace WritebackModel
{
    public partial class WritebackModel : Page
    {
        ...
        public static void Page_Load(object sender, EventArgs e)
        {
            /* Call the appropriate function for the page */
            Debug.WriteLine("Called Pageload function");
            Writeback_MissingWork();
        }
    }
}

Nothing is being written to the console debug.控制台调试没有写入任何内容。

From this https://www.c-sharpcorner.com/UploadFile/8911c4/page-life-cycle-with-examples-in-Asp-Net/从这个https://www.c-sharpcorner.com/UploadFile/8911c4/page-life-cycle-with-examples-in-Asp-Net/

You can try to remove the "static" in Page_Load() method.您可以尝试删除 Page_Load() 方法中的“静态”。

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

相关问题 ASP.NET C#从Code Behind设置OnSelectedIndexChanged - ASP.NET C# Set OnSelectedIndexChanged from Code Behind 没有在ASP.NET代码中动态设置CSS样式 - CSS Style not being set Dynamically in ASP.NET Code behind 使用ASP.Net和C#在代码中将Data URI设置为asp:Image - Set Data URI to asp:Image in code behind using ASP.Net and C# 设置文字 <p> 从c#asp.net中的代码嵌入在asp:Panel中 - Set text in <p> embedded in asp:Panel from code behind c# asp.net 如何在ASP.NET中以C#作为代码,以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength” - How to programmatically set (using GET SET property) “httpRuntime maxRequestLength” in ASP.NET with C# as code behind 在ASP.Net的page指令中应将AutoEventWireup设置为什么值? - What value should AutoEventWireup be set to in the page directive in ASP.Net? 如何在C#ASP.NET背后的代码中将背景图像设置为:: before选择器 - How to set background-image to ::before selector in code behind C# ASP.NET 从C#Asp.net后面的代码设置输入文本字段的值 - Set the value of input text field from code behind C# Asp.net 如何在javascript中设置asp.net隐藏字段并访问c#代码后面的值 - how to set asp.net hidden field in javascript and access the value in c# code behind 在C#asp.net中编写代码的Javascript - Javascript to code behind in c# asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM