Page_Load(...) not executed in MainWebForm.aspx

Discussion in 'ASP .Net' started by Richard Lionheart, Oct 13, 2005.

  1. Hi All,

    I adapted some sample code from w3schools.com and tried to adapt it to .NET
    to test dynamic processing in a WebForm. The client page that got generated
    produced everything that was coded except for displaying the time at which
    it was generated. I tried everything I could think of to rewrite this and
    to debug this.

    Anyone out there in Cyberspace got any idea why the time doesn't get
    displayed. The .aspx code follows below

    Thanks in Advance,
    Richard

    ======== MainWebForm.aspx ===============
    <%@ Page language="c#" Codebehind="MainWebForm.aspx.cs"
    AutoEventWireup="false" Inherits="TestDynamicTimeReporting2.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Dynamic-Time Form</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">

    <script language="C#" runat="server">
    void Page_Load(Object Src, EventArgs E) {
    MyTimeLabel.Text = "You last accessed this page at: " +
    DateTime.Now;
    }
    </script>

    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="MyForm" method="post" runat="server">
    <asp:Label id="MyTopLabel" style="Z-INDEX: 101; LEFT: 160px;
    POSITION: absolute; TOP: 19px" runat="server" Width="429px" Height="25px">
    <h1>Test Dynamic Time Reporting</h1>
    </asp:Label>
    <asp:Label id="MyTimeLabel" style="Z-INDEX: 102; LEFT: 291px;
    POSITION: absolute; TOP: 102px" runat="server" Width="190px" Height="22px"
    ForeColor="Red">The time is ...........................</asp:Label>
    <asp:Button id="MyButton" style="Z-INDEX: 103; LEFT: 326px;
    POSITION: absolute; TOP: 198px" runat="server" Width="106px" Height="33px"
    Text="Update the time"></asp:Button>
    </form>
    </body>
    </HTML>


    =================== MainWebForm.aspx =========================

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace TestDynamicTimeReporting2
    {
    /// <summary>
    /// Summary description for MainWebForm.
    /// </summary>
    public class MainWebForm : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label MyTopLabel;
    protected System.Web.UI.WebControls.Label MyTimeLabel;
    protected System.Web.UI.WebControls.Button MyButton;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
    }
    }
     
    Richard Lionheart, Oct 13, 2005
    #1
    1. Advertising

  2. Richard Lionheart

    Karl Seguin Guest

    If you want ur <Script runat="Server"...> to work, you need to set
    AutoEventWireUp to true in the @Page directive.

    I don't think there's any good reason to use both inline code (<script
    runat="server">...</script>) and codebehind (the MainWebForm.aspx.cs)
    Decide which methodology you want to use and stick with it (I prefer the
    codebehind, and so does Visual Studio .Net). Therefore, if you simply
    removed ur <script runat="Server"... and put the MyTimeLabel.Text = "You
    last accessed this page at: " + DateTime.Now in the Page_Load of the .cs
    file and recompiled everything should work.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



    "Richard Lionheart" <> wrote in message
    news:...
    > Hi All,
    >
    > I adapted some sample code from w3schools.com and tried to adapt it to
    > .NET to test dynamic processing in a WebForm. The client page that got
    > generated produced everything that was coded except for displaying the
    > time at which it was generated. I tried everything I could think of to
    > rewrite this and to debug this.
    >
    > Anyone out there in Cyberspace got any idea why the time doesn't get
    > displayed. The .aspx code follows below
    >
    > Thanks in Advance,
    > Richard
    >
    > ======== MainWebForm.aspx ===============
    > <%@ Page language="c#" Codebehind="MainWebForm.aspx.cs"
    > AutoEventWireup="false" Inherits="TestDynamicTimeReporting2.WebForm1" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>Dynamic-Time Form</title>
    > <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    > <meta name="CODE_LANGUAGE" Content="C#">
    > <meta name="vs_defaultClientScript" content="JavaScript">
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    >
    > <script language="C#" runat="server">
    > void Page_Load(Object Src, EventArgs E) {
    > MyTimeLabel.Text = "You last accessed this page at: " +
    > DateTime.Now;
    > }
    > </script>
    >
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="MyForm" method="post" runat="server">
    > <asp:Label id="MyTopLabel" style="Z-INDEX: 101; LEFT: 160px;
    > POSITION: absolute; TOP: 19px" runat="server" Width="429px" Height="25px">
    > <h1>Test Dynamic Time Reporting</h1>
    > </asp:Label>
    > <asp:Label id="MyTimeLabel" style="Z-INDEX: 102; LEFT: 291px;
    > POSITION: absolute; TOP: 102px" runat="server" Width="190px" Height="22px"
    > ForeColor="Red">The time is ...........................</asp:Label>
    > <asp:Button id="MyButton" style="Z-INDEX: 103; LEFT: 326px;
    > POSITION: absolute; TOP: 198px" runat="server" Width="106px" Height="33px"
    > Text="Update the time"></asp:Button>
    > </form>
    > </body>
    > </HTML>
    >
    >
    > =================== MainWebForm.aspx =========================
    >
    > using System;
    > using System.Collections;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Web;
    > using System.Web.SessionState;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    >
    > namespace TestDynamicTimeReporting2
    > {
    > /// <summary>
    > /// Summary description for MainWebForm.
    > /// </summary>
    > public class MainWebForm : System.Web.UI.Page
    > {
    > protected System.Web.UI.WebControls.Label MyTopLabel;
    > protected System.Web.UI.WebControls.Label MyTimeLabel;
    > protected System.Web.UI.WebControls.Button MyButton;
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > }
    >
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > //
    > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    > //
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    >
    > }
    > #endregion
    > }
    > }
    >
    >
    >
     
    Karl Seguin, Oct 13, 2005
    #2
    1. Advertising

  3. Hi Karl,

    Thank you for the perfect answer to my quandary. I will clean up this
    example I got from W3Schools.com, both ways -- one using script exclusively
    and the other only code-behind -- just so I'm up-to-speed on this aspect.

    Thank you also for you references to openmind.net. I am interested in XML
    under .NET, so AJAX is right up my alley.

    Instead of just copying your corrections, I made modifications myself,
    which led to one more question about the scripting version. What I did was:

    1. I modified the AutoEventWireup as you suggested and that of course broke
    the log jam.

    2. The original example presented a refreshed server-built client page every
    time the button was clicked, which led the then-current time at the server
    to be presented on the client page.

    3. I updated the example to have original-server-time for the first client
    page presented with every updated client page. If I had known how, I would
    have created a static variable initialized to upon creation of the first
    page. The not-really-so-kludgey way I did was to modify OnPageLoad as
    follows:
    void Page_Load(Object Src, EventArgs E) {
    MyTimeLabel.Text = "You updated this page at: " + DateTime.Now;
    if (MyTextLabel.Text == "")
    { MyTextLabel.Text = "The orignal page was cre-ated" +
    DateTime.Now; }
    }

    Was there a simple way do define and initialize a static variable with the
    time of the first page's creation. In scripting? While we're at it, how
    about in code-behind?

    Thanks again,
    Richard
     
    Richard Lionheart, Oct 15, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. taja

    ASPX not executed

    taja, Oct 22, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    1,977
    Rajesh.V
    Oct 22, 2003
  2. =?Utf-8?B?TWFnZXNo?=
    Replies:
    0
    Views:
    371
    =?Utf-8?B?TWFnZXNo?=
    Aug 25, 2004
  3. Replies:
    3
    Views:
    592
    Terry Burns
    Feb 3, 2006
  4. Jeff

    Page_Load not executed

    Jeff, May 4, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    495
    Cowboy \(Gregory A. Beamer\)
    May 4, 2009
  5. taja

    ASPX not executed

    taja, Oct 22, 2003, in forum: ASP General
    Replies:
    1
    Views:
    94
    Ray at
    Oct 22, 2003
Loading...

Share This Page