Accessing BODY element from server side code?

  • Thread starter Thread starter rolf.oltmans
  • Start date Start date
R

rolf.oltmans

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
 
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>
 
Back
Top