Run code from ASPX page

M

Mark Goldin

I am very new to ASP.NET. Here is what I am trying to do:
This my Default.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
%>

<!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>
</div>
</form>
</body>
</html>

and this is Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PrintLawLabels
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// some code
}
}
}

How can I run Page_Load method when a default.aspx is loaded?

Thanks
 
G

Guest

I am very new to ASP.NET. Here is what I am trying to do:
This my Default.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
%>

<!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>
        </div>
    </form>
</body>
</html>

and this is Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PrintLawLabels
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // some code
        }
    }

}

How can I run Page_Load method when a default.aspx is loaded?

Thanks

ASP.NET automatically calls Page_Load and execute the code inside it.
http://msdn.microsoft.com/en-us/library/ms178472.aspx
 
M

Mark Goldin

How can I test that? How can I have an alert box or something that will show
that Page_Load is running?

I am very new to ASP.NET. Here is what I am trying to do:
This my Default.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
%>

<!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>
</div>
</form>
</body>
</html>

and this is Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PrintLawLabels
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// some code
}
}

}

How can I run Page_Load method when a default.aspx is loaded?

Thanks

ASP.NET automatically calls Page_Load and execute the code inside it.
http://msdn.microsoft.com/en-us/library/ms178472.aspx
 
J

Juan T. Llibre

re:
!> > How can I test that?

Run a trace on the page.

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

When you run the page, you'll see timings for :

Begin Load
End Load
Begin LoadComplete
End LoadComplete



===============
 
G

Gregory A. Beamer

How can I test that? How can I have an alert box or something that
will show that Page_Load is running?

Open Visual Studio (Visual Web Developer Express) and set a breakpoint on a
line in Page_Load. If it hits the breakpoint, it is running.

If you are hand coding, you can use Response.Write() to see something in
the browser, but Express is free from Microsoft, so I see no reason not to
use a tool to program with.

peace and grace,
 
A

Andrew Morton

Mark said:
How can I test that?

Your "some code" will have done something.
How can I have an alert box or something that will show that Page_Load
is running?

I tend to put an asp:literal control at the end of a page and write to its
..text (with the time, too).

Andrew
 
G

Guest

How can I test that? How can I have an alert box or something that will show
that Page_Load  is running?

Add Response.Write("Hello, world") into it. And see what happens
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top