Re: How to call C# function from Javascript;

From: Dale Preston (dalepres_at_nospam.nospam)
Date: 03/23/05


Date: Tue, 22 Mar 2005 18:58:04 -0600

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$jervLFHA.1180@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" <mohamed.mossad@egdsc.microsoft.com> wrote in message
> news:jSD80YsLFHA.380@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
> >
>
>