469,362 Members | 2,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

Is possible to call asp.net(c#) function in HTML.....


This is inbaraj from India. I want to know is it possible to run C# functions in HTML. Plz help me.....

If yes let me know the sample codeing....

Thanks in advance...

with regards
Job Seeker
Jun 1 '07 #1
2 4318
4,871 Expert 4TB
The short answer is no, html being client side. What are you trying to do?
Jun 1 '07 #2
You should be able to. I've done it with VB so you should be able to do it in C#. Here's an example:

In my html I have:
<div id="Hello" onmouseover="<%# (GetMouseOverJavascriptFn()) %>" onmouseout="<%# (GetMouseOutJavascriptFn()) %>" runat="server">

In my code behind I have:
Protected Function GetMouseOverJavascriptFn() As String

return = "document.getElementById('elemId').style.visibilit y='visible'"

End Function

Protected Function GetMouseOutJavascriptFn() As String

return = "document.getElementById('elemId').style.visibilit y='hidden'"

End Function

This is the only context in which I've done it. So the key is you put your function in <%# functionName %>
However, the thing to remember is that VB/C# are server-side so you cannot call them as you would a JavaScript function. The functions in the example above get run the first time the page is generated. Once the page is running on the client machine, the only way you can call VB/C# functions is through a postback to the server.

Jun 1 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Alison Givens | last post: by
8 posts views Thread by dbaplusplus | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.