473,473 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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="javascript">
private void Page_Load(object sender, System.EventArgs
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

Nov 15 '05 #1
3 1342
Page_Load is a server side event. object sender and System.EventArgs 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/
Nov 15 '05 #2
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(Object Src, EventArgs E)
{
// Create a connection to the "pubs" SQL database
located on
// the local computer.
myConnection = new SqlConnection("Server=Pluto;User
ID=sa;Password=sa;Database=pubs");
myConnection.Open();
// 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.Open();
Exectuio statements goes here...
}

</script>

Thanks,
Ramesh
-----Original Message-----
Page_Load is a server side event. object sender and System.EventArgs makeno meaning for the client.

You would write things that happen on the web server in source code andthings 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 thepage isn't sent just yet, whereas script is run after the page is sent tothe client. As far as the server know, the page doesn't exist anymore andis destroyed on the server (unless you take special precautions).
My guess is that you won't receive any error because the script functionjust waits for anything calling Page_Load, but nothing will call thisfunction on the client.

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

Nov 15 '05 #3
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.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 TestWebApp
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;

protected void Page_Load(Object Src, EventArgs E) {
// Create a connection to the "pubs" SQL database // located on the
local computer.
myConnection = new SqlConnection("Server=Pluto;User
ID=sa;Password=sa;Database=pubs");
myConnection.Open();
// 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.Open();
//Exectuio statements goes here...
}

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

private void InitializeComponent()
{ this.Load += new System.EventHandler(this.Page_Load);

}
}
}

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SteveJ | last post by:
All, Can someone help me solve the next step. First of all let me say I'm new to php. I pieced the following code together from samples I found on the net and a book I bought called PHP...
2
by: Jon Haakon | last post by:
Hi, I'm developing a websolution using ASP and DHTML technology that's running on a MS IIS webserver. My solution is frame based with a toolbar on top, a hidden frame for scripts in the...
1
by: Randi | last post by:
Hi all, I there any way of putting an html hyperlink into a .xml file, and still be able to use the xml tags to format the page? Here is the code of the xml file(real simple) and the .css file. ...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: mca | last post by:
Hi everyone, I'm new to asp.net and i have a question about separating the html code from the programming code. i have an unknown numbers of entries in my table. I want to make a hyperlink...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
17
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
42
by: Santander | last post by:
how to decode HTML pages encoded like this: http://www.long2consulting.com/seeinaction2008/Simplicity_Beach_table/index.htm Is there script that will do this automatically and generate normal fully...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.