[英]ASP.NET C# Button OnClick No Response, No Value Change
我用 ASP.NET C# 建立了一個簡單的網站。
我在 Visual Studio 中按 [RUN] 后它運行正常。
但是,在我上傳到我的 web 托管服務器后,單擊按鈕時沒有任何反應。 “Label1”沒有改變任何東西。 好像沒有回帖。
發生什么了? 錯過了什么?
這是 Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyWebApp._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
這是 Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BiLab
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Button 1 Pressed.";
}
}
}
這是我的 Web.Config:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="false"/>
<pages enableViewState="true"/>
<sessionState cookieless="UseCookies" cookieName="MyWebApp" timeout="20" />
<authentication mode="Windows" />
<customErrors mode="Off"/>
</system.web>
</configuration>
在后面的代碼中檢查您的命名空間。 它是:BILab 和 Default.aspx 中的 Inherits="MyWebApp._Default" 屬性不匹配。
改變:
<%@ Page Language="C#"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="MyWebApp._Default" %>
到:
<%@ Page Language="C#"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="BILab._Default" %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.