I was working on an ASP.NET page and the code behind was executing properly. 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. 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? 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:
<%@ 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:
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
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/
You can try to remove the "static" in Page_Load() method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.