1

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>

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.