Accessing BODY element from server side code?

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
 
E

Eliyahu Goldin

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top