469,306 Members | 2,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to call C# function from Javascript;

Hello,

How to call a C# function (eg., main()) from a Javascript funtion (eg.,
ref()).

-- Steven
Nov 16 '05 #1
4 35754
Hi Steven
C# is complied language not just interpreted script language as JavaScript
Therefore, i don't think you can do that , the opossite is easy however.
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 17 '05 #2
In one of the webiste I have seen something like this to call C# function
from Javascript :
--------------------------------------------------------
<script language="javascript">
function init()
{
alert('hello ');
<%SetData();%>; //------------------------------> main line
alert('<%=strName%>');
}
</script>
-------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
this.ImageButton1.Attributes.Add("onclick",
"javascript:init();");
}
}
public void SetData()
{
strName = "mainpico";
}
But when I try to replicate the same .. I'm getting error in the main line.
How can I achieve the same?
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:jS*************@TK2MSFTNGXA02.phx.gbl...
Hi Steven
C# is complied language not just interpreted script language as
JavaScript
Therefore, i don't think you can do that , the opossite is easy however.
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 17 '05 #3
Is your SetData() method set as public or protected? If it is private you
cannot access it in the ASPX page.

Dale Preston

"Steven" <counterball_20122@_hotmail.com> wrote in message
news:uz**************@TK2MSFTNGP14.phx.gbl...
In one of the webiste I have seen something like this to call C# function
from Javascript :
--------------------------------------------------------
<script language="javascript">
function init()
{
alert('hello ');
<%SetData();%>; //------------------------------> main line
alert('<%=strName%>');
}
</script>
-------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
this.ImageButton1.Attributes.Add("onclick",
"javascript:init();");
}
}
public void SetData()
{
strName = "mainpico";
}
But when I try to replicate the same .. I'm getting error in the main line. How can I achieve the same?
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:jS*************@TK2MSFTNGXA02.phx.gbl...
Hi Steven
C# is complied language not just interpreted script language as
JavaScript
Therefore, i don't think you can do that , the opossite is easy however. Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC


Nov 17 '05 #4
I set SetData method as public.

_- Steven

"Dale Preston" <da******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Is your SetData() method set as public or protected? If it is private you
cannot access it in the ASPX page.

Dale Preston

"Steven" <counterball_20122@_hotmail.com> wrote in message
news:uz**************@TK2MSFTNGP14.phx.gbl...
In one of the webiste I have seen something like this to call C# function
from Javascript :
--------------------------------------------------------
<script language="javascript">
function init()
{
alert('hello ');
<%SetData();%>; //------------------------------> main
line
alert('<%=strName%>');
}
</script>
-------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
this.ImageButton1.Attributes.Add("onclick",
"javascript:init();");
}
}
public void SetData()
{
strName = "mainpico";
}
But when I try to replicate the same .. I'm getting error in the main

line.
How can I achieve the same?
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:jS*************@TK2MSFTNGXA02.phx.gbl...
> Hi Steven
> C# is complied language not just interpreted script language as
> JavaScript
> Therefore, i don't think you can do that , the opossite is easy however. > Mohamed M .Mahfouz
> Developer Support Engineer
> ITWorx on behalf of Microsoft EMEA GTSC
>



Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by chirs | last post: by
3 posts views Thread by KaNos | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.