Page_Load not called

C

coltrane

I am just learing ASP.Net and my first app has a simple Page_Load that
just sets a variable. This does not seem to be called. The following is
a snippet of the page:

<script runat="server" language="C#">
void Page_Load(){
Message.Text = "This is a message";
}
</script>

<body>
<asp:Label ID="Message" Runat="server" />
</body>


This seems pretty basic. What might be the problem?

thanks for the help

jc
 
C

coltrane

Thanks,

I tried that a few times.

jc

Compile first and see if that helps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBAhttp://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
 
G

Gaurav Vaish \(MasterGaurav\)

I am just learing ASP.Net and my first app has a simple Page_Load that
just sets a variable. This does not seem to be called. The following is
a snippet of the page:

<script runat="server" language="C#">
void Page_Load(){
Message.Text = "This is a message";
}
</script>

Do you have you any codebehind / codebeside?
Look into the @Page directive...

btw, what is the output that you get?
Can you explain what do you mean when you say "that just sets a variable"?

I just tried with the code below and it works perfectly fine.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load()
{
helloLbl.Text = "Hello, World";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Page_Load Testing</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="helloLbl" runat="server" />
</div>
</form>
</body>
</html>

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
C

coltrane

I am just learing ASP.Net and my first app has a simple Page_Load that
just sets a variable. This does not seem to be called. The following is
a snippet of the page:
<script runat="server" language="C#">
void Page_Load(){
Message.Text = "This is a message";
}
</script>

Do you have you any codebehind / codebeside?
Look into the @Page directive...

btw, what is the output that you get?
Can you explain what do you mean when you say "that just sets a variable"?

I just tried with the code below and it works perfectly fine.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load()
{
helloLbl.Text = "Hello, World";}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Page_Load Testing</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="helloLbl" runat="server" />
</div>
</form>
</body>
</html>

Gaurav,

thank you for your reply.

I used the following for my page:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="Test.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<script runat="server" language="C#">
void Page_Load(){
Message.Text = "this is a message ";
}
</script>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET
7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://
schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<asp:Label ID="Message" Runat="server" />

I found that if I changed the first line:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="Test.WebForm1" %>
to
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" %>

the message "This is a Message" is displayed.
Now I have to find out why this occurs.

thanks again

john
 
M

MasterGaurav \(www.edujini-labs.com\)

I found that if I changed the first line:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="Test.WebForm1" %>
to
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" %>


"AutoEventWireup" is the culprit.
Look into the documentation of "@ Page" directive and you'll get all answers
to the mystery.

I'll probably put this in my FAQ. I've seen this mistake done several times
:)


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
C

coltrane

"AutoEventWireup" is the culprit.
Look into the documentation of "@ Page" directive and you'll get all answers
to the mystery.

I'll probably put this in my FAQ. I've seen this mistake done several times
:)

thanks
 
C

coltrane

"AutoEventWireup" is the culprit.
Look into the documentation of "@ Page" directive and you'll get all answers
to the mystery.

I'll probably put this in my FAQ. I've seen this mistake done several times
:)

Gaurav,

I have found that I must also remove the inherits directive also.
 
C

coltrane

"AutoEventWireup" is the culprit.
Look into the documentation of "@ Page" directive and you'll get all answers
to the mystery.

I'll probably put this in my FAQ. I've seen this mistake done several times
:)

me again, I figured it out. now I know about Web Forms page and
"single-file" web forms page

thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top