HTML page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramesh

    #1

    HTML page

    hi,
    I have some basic questions. Can anybody explain me the
    following doubt:

    1. In my asp page, right click and selected HTML source
    code.
    Added following method.
    <script language="javas cript">
    private void Page_Load(objec t sender, System.EventArg s
    e)
    {
    alert('hi');
    }
    when i run the application, i am not getting the
    message "hi" and it is not displaying any error message.
    but, if righ client and added this source code in "View
    code" then i am getting this message. why? If we write
    Page_Load method in HTML source code, then it won't
    execute??

    2. What is the difference between writting the above
    method in HTML source code and View Code. What is the
    purpose of View code? any why i am not getting error
    message or "hi" message?

    Thanks,
    Ramesh

  • Morten Wennevik

    #2
    Re: HTML page

    Page_Load is a server side event. object sender and System.EventArg s make
    no meaning for the client.

    You would write things that happen on the web server in source code and
    things that happen on the client side in html script.

    Page_Load is run when a page is about to be sent to the client, but the
    page isn't sent just yet, whereas script is run after the page is sent to
    the client. As far as the server know, the page doesn't exist anymore and
    is destroyed on the server (unless you take special precautions).

    My guess is that you won't receive any error because the script function
    just waits for anything calling Page_Load, but nothing will call this
    function on the client.

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    • Ramesh

      #3
      Re: HTML page

      hi,
      Thanks for your reply. So, if i write the following
      method in HTML source code, then it won't execute? and the
      connection object wound't be initialised in
      AddAuthor_Click event? is it correct? If so, how to do it
      in the HTML source code page (instead of View code).

      <script language="C#" runat="server">
      SqlConnection myConnection;
      protected void Page_Load(Objec t Src, EventArgs E)
      {
      // Create a connection to the "pubs" SQL database
      located on
      // the local computer.
      myConnection = new SqlConnection(" Server=Pluto;Us er
      ID=sa;Password= sa;Database=pub s");
      myConnection.Op en();
      // Check to see whether this page is a postback. If
      it is not
      // a postback, call a custom BindGrid function.
      if (!IsPostBack) BindGrid();
      }

      public void AddAuthor_Click (Object sender, EventArgs E)
      {
      Command object initialisation code here...
      myConnection.Op en();
      Exectuio statements goes here...
      }

      </script>

      Thanks,
      Ramesh
      [color=blue]
      >-----Original Message-----
      >Page_Load is a server side event. object sender and[/color]
      System.EventArg s make[color=blue]
      >no meaning for the client.
      >
      >You would write things that happen on the web server in[/color]
      source code and[color=blue]
      >things that happen on the client side in html script.
      >
      >Page_Load is run when a page is about to be sent to the[/color]
      client, but the[color=blue]
      >page isn't sent just yet, whereas script is run after the[/color]
      page is sent to[color=blue]
      >the client. As far as the server know, the page doesn't[/color]
      exist anymore and[color=blue]
      >is destroyed on the server (unless you take special[/color]
      precautions).[color=blue]
      >
      >My guess is that you won't receive any error because the[/color]
      script function[color=blue]
      >just waits for anything calling Page_Load, but nothing[/color]
      will call this[color=blue]
      >function on the client.
      >
      >--
      >Using M2, Opera's revolutionary e-mail client:[/color]
      http://www.opera.com/m2/[color=blue]
      >.
      >[/color]

      Comment

      • Morten Wennevik

        #4
        Re: HTML page

        I'm not sure what happens if you put runat="server" in a script, but
        I think you would want something like this in html code

        <asp:Button id="AddAuthor" runat="server" Text="Add Author"></asp:Button>

        and then have this in your webpage.aspx.cs file

        using System;
        using System.Collecti ons;
        using System.Componen tModel;
        using System.Data;
        using System.Drawing;
        using System.Web;
        using System.Web.Sess ionState;
        using System.Web.UI;
        using System.Web.UI.W ebControls;
        using System.Web.UI.H tmlControls;

        namespace TestWebApp
        {
        public class WebForm1 : System.Web.UI.P age
        {
        protected System.Web.UI.W ebControls.Butt on Button1;

        protected void Page_Load(Objec t Src, EventArgs E) {
        // Create a connection to the "pubs" SQL database // located on the
        local computer.
        myConnection = new SqlConnection(" Server=Pluto;Us er
        ID=sa;Password= sa;Database=pub s");
        myConnection.Op en();
        // Check to see whether this page is a postback. If it is not // a
        postback, call a custom BindGrid function.
        if (!IsPostBack) BindGrid();
        }
        public void AddAuthor_Click (Object sender, EventArgs E) {
        //Command object initialisation code here...
        myConnection.Op en();
        //Exectuio statements goes here...
        }

        override protected void OnInit(EventArg s e)
        {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeCompo nent();
        base.OnInit(e);
        }

        private void InitializeCompo nent()
        { this.Load += new System.EventHan dler(this.Page_ Load);

        }
        }
        }

        --
        Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

        Comment

        Working...