ASP.NET and mouseover

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
I wrote some code in C#:
Code:
<%@ Page Language="C#" %>
<script runat="server">
 
	void myAction(Object Sender, EventArgs e) {
	 if (Sender.Equals("theBody")) {
		 testArea.InnerHtml = "The body works.";
	 } else
	 if (Sender.Equals("myLink")) {
		 testArea.InnerHtml = "The link works.";
	 }
	}
 
</script>
<html>
<head>
</head>
<body id="theBody" onload="myAction" runat="server">
	<asp:Hyperlink id="myLink" onmouseover="myAction" runat="server" NavigateUrl="" Text="Test" />
	<span id="testArea" runat="server" />
</body>
</html>
...but this gives me an error in Internet Explorer, saying "Error: 'myAction' is undefined". When I select "View Source", obviously the C# script is not displayed.

How can I allow my C# code to be accessed by the form? Does anyone even understand what I am trying to ask? Is this possible in ASP.NET/C# ... or whatever you want to call it.
 
You are confusing server-side code with client-side code. Client-side code is typically with JavaScript or VBScript and then "hooked" into from C#.

"onmouseover" is a client side event that can be raised by the client-side code.

ASP.NET has a function "RegisterClientSideScript" that you can feed some JavaScript into. Once you have a valid client-side function associated with the page, you can make calls to it through C# with something like this:
Code:
btnSubmit.Attributes.Add("onClick","myJScriptFunction()");
 
So, using "RegisterClientSideScript", something like:
Code:
theBody.Attributes.Add("onload", "myAction()");
might enable me to "mix" my client/server side functions? I'll have wait until later to look up "RegisterClientSideScript" - I am allowed "Borland only" here at work.

Your btnSubmit has an ASP.NET tag in the html page, but all my body tag has is id=theBody.

Currently, I write to span's InnerHtml using the body's onload and the hyperlink's mouseover events in JavaScript. This leaves my work exposed for others to grab, and I have to write different versions for IE and Netscape. Using C#, I want to try varybycustom="browser" so that .NET will taylor its output to the particular browser. That would save me a LOT of time in development.
 
Back
Top