alont
alont

Reputation: 263

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>

Upvotes: 1

Views: 1769

Answers (2)

Code Maverick
Code Maverick

Reputation: 20415

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" %>

Upvotes: 0

Ashwini Verma
Ashwini Verma

Reputation: 7525

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

Upvotes: 1

Related Questions