By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,880 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,880 IT Pros & Developers. It's quick & easy.

Accessing BODY element from server side code?

P: n/a
Hello,

I've been trying to access the html element "Body" in my server side
code. I've searched the archives of this group and have been able to
put together an example that doesn't work :)
Actually, I am want to raise an event at client side and want to
perform some action on the server side when that event at client is
triggered. So here is what I am trying to do,
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="__Default"%>
<html>
<head>
</head>
<body runat="server" id="mybody">

<form id="form1" action="Default.aspx" runat="server" method="post">
</form>
</html>
---
Now in my code behind file, I wrote

public partial class __Default : System.Web.UI.Page
{

void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl mybody = new HTMLGenericControl();
mybody.Attributes.Add("onload","javascript:alert(' hello !
');");
}
}

But nothing seems to be working , page loads and alert message doesn't
show up. What I am missing here?
Any help will be highly appreciated.

--Oltmans
P.S --I am working on ASP.NET 2.0

Oct 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
<ro**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
HtmlGenericControl mybody = new HTMLGenericControl();
Take this line out.
Oct 14 '06 #2

P: n/a
Hello Mark,

HtmlGenericControl mybody = new HTMLGenericControl();

Take this line out.
I took this out but it didn't work, any insight ?

Anybody else ?
--Oltmans

Oct 14 '06 #3

P: n/a
If all you want is just to produce an alert box when the page loads, have
you javascript code in the aspx page and pass the message from the server
side in a hidden input control:

<head>
<script>
function doOnLoad(){
if (form1.inhMessage.value!='')
alert (form1.inhMessage.value);
}
</script>
</head>
<body onload="doOnLoad()">
<form id="form1" ...>
....
<input type="hidden" runat="server" id="inhMessage" />
</form>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<ro**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello,

I've been trying to access the html element "Body" in my server side
code. I've searched the archives of this group and have been able to
put together an example that doesn't work :)
Actually, I am want to raise an event at client side and want to
perform some action on the server side when that event at client is
triggered. So here is what I am trying to do,
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="__Default"%>
<html>
<head>
</head>
<body runat="server" id="mybody">

<form id="form1" action="Default.aspx" runat="server" method="post">
</form>
</html>
---
Now in my code behind file, I wrote

public partial class __Default : System.Web.UI.Page
{

void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl mybody = new HTMLGenericControl();
mybody.Attributes.Add("onload","javascript:alert(' hello !
');");
}
}

But nothing seems to be working , page loads and alert message doesn't
show up. What I am missing here?
Any help will be highly appreciated.

--Oltmans
P.S --I am working on ASP.NET 2.0

Oct 15 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.