joe_pool_is Posted April 14, 2005 Posted April 14, 2005 I wrote some code in C#: <%@ 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. Quote Avoid Sears Home Improvement
Mister E Posted April 14, 2005 Posted April 14, 2005 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:btnSubmit.Attributes.Add("onClick","myJScriptFunction()"); Quote
joe_pool_is Posted April 14, 2005 Author Posted April 14, 2005 So, using "RegisterClientSideScript", something like: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. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.