PC Review


Reply
Thread Tools Rate Thread

How to call C# function from Javascript;

 
 
Steven
Guest
Posts: n/a
 
      22nd Mar 2005
Hello,

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

-- Steven


 
Reply With Quote
 
 
 
 
Mohamoss
Guest
Posts: n/a
 
      22nd Mar 2005
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

 
Reply With Quote
 
Steven
Guest
Posts: n/a
 
      22nd Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Dale Preston
Guest
Posts: n/a
 
      23rd Mar 2005
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$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >

>
>



 
Reply With Quote
 
Steven
Guest
Posts: n/a
 
      23rd Mar 2005
I set SetData method as public.

_- Steven

"Dale Preston" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call JavaScript Function Mike McIntyre Microsoft ASP .NET 5 21st Aug 2007 12:16 PM
Call javascript function without using any event call cschang Microsoft ADO .NET 3 1st Feb 2005 03:04 AM
How to call a Javascript function in VB? prince -=nore=- Microsoft ASP .NET 1 4th Feb 2004 03:41 AM
How To Call Javascript function in asp.net hrishikesh Microsoft ASP .NET 1 15th Jan 2004 06:48 AM
Call C# function from Javascript Kannan Microsoft C# .NET 1 24th Dec 2003 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 PM.