How to call C# function from Javascript;

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

Hello,

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

-- Steven
 
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
 
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?
 
Is your SetData() method set as public or protected? If it is private you
cannot access it in the ASPX page.

Dale Preston
 
I set SetData method as public.

_- Steven

Dale Preston said:
Is your SetData() method set as public or protected? If it is private you
cannot access it in the ASPX page.

Dale Preston
 
Back
Top