ASP.NET C#按钮OnClick没有响应,没有值更改

时间:2012-04-07 02:47:05

标签: c# asp.net

我用ASP.NET C#构建了一个简单的网站。

在Visual Studio中按[RUN]后,它正常运行。

但是,在我上传到我的网络托管服务器后,单击该按钮时没有任何反应。 “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>

2 个答案:

答案 0 :(得分:1)

在后面的代码中检查您的命名空间。它是:BILab 和Default.aspx中的Inherits =“MyWebApp._Default”属性不匹配。

答案 1 :(得分:0)

变化:

<%@ Page Language="C#" 
         AutoEventWireup="true" 
         CodeBehind="Default.aspx.cs" 
         Inherits="MyWebApp._Default" %>

为:

<%@ Page Language="C#" 
         AutoEventWireup="true" 
         CodeBehind="Default.aspx.cs" 
         Inherits="BILab._Default" %>
相关问题