简体   繁体   English

在ASP.NET中未执行Page_Load

[英]Page_Load is not executed in asp.net

I have this c# code 我有这个C#代码

namespace ZumaApp
{

    public partial class _Default : System.Web.UI.Page
    {
        ServiceReference1.QSLWebBookingSoapClient services;
        public String CallerId = "";
        public Int32 rowCount;
        protected void Page_Load(object sender, EventArgs e)
        {
            CallerId = Request["CallerID"];

and in my asp I have this: 在我的ASP中,我有这个:

<%@ Page Title="VMP Online Booking" Language="C#" MasterPageFile="~/Site.master"
    AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ZumaApp._Default" %>

My problem 我的问题

The page load function is not executing. 页面加载功能未执行。

how did I know that 我怎么知道

First: I make a break point on the first line in the Page_Load function, but visual studio doesn't stop at the break point. 首先:我在Page_Load函数的第一行上创建了一个断点,但是Visual Studio并没有在该断点处停止。

second: I make a break point at this line public String CallerId = ""; 第二个:我在这行做一个断点public String CallerId = ""; and Visual studio stops on that line, then I press step over but the page loaded without going to the Page_Load function. 然后Visual Studio停在那条线上,然后按“ step over但页面已加载,而没有转到Page_Load函数。

I tried clean and rebuild but dones't help 我尝试清理并重建,但没有帮助

try this 尝试这个

<%@ Page Title="VMP Online Booking" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="_Default.aspx.cs" Inherits="ZumaApp._Default" %>

Try delete the .Designer.cs and recreate it by Convert to web application option. 尝试删除.Designer.cs ,然后通过“转换为Web应用程序”选项重新创建。

It can be regenerated by right clicking on the aspx / ascx file and select Convert to web application option. 可以通过右键单击aspx / ascx文件并选择转换为Web应用程序选项来重新生成它。

Some times .Designer.cs wont be refreshed by VS, and need to apply this method to get a fresh .Designer.cs file. 有时,VS无法刷新.Designer.cs ,因此需要应用此方法来获取新的.Designer.cs文件。

In the InitializeComponent function (which resides in the "Web Form Designer generated code" region), you should have a line which says: InitializeComponent函数(位于“ Web窗体设计器生成的代码”区域中)中,您应该有一行显示:

this.Load += new System.EventHandler(this.Page_Load);

This line of code should be automatically generated, and tells the framework to execute the Page_Load function when the page loads. 这行代码应自动生成,并告诉框架在页面加载时执行Page_Load函数。 If this line is missing, the Page_Load function won't fire. 如果缺少此行,则不会触发Page_Load函数。 Adding this line should solve your problem. 添加此行应该可以解决您的问题。

Reference: Page_Load Not Firing? 参考: Page_Load不触发?

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

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