简体   繁体   中英

ASP.NET C# Button OnClick No Response, No Value Change

I have build a simple website with ASP.NET C#.

It runs normally after I pressed [RUN] in Visual Studio.

But, after I uploaded to my web hosting server, nothing happens when the button is clicked. The "Label1" is not changing anything. It seems to be no post back.

What happens? What is missed?

here is the 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>

And this is 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.";
        }
    }
}

This is my 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>

check your namespace in code behind. It is: BILab and Inherits="MyWebApp._Default" attribute in Default.aspx it doesn't match.

Change:

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

to:

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

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.

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