implement the ICallbackEventHandler in the page and derive the two Events which
are RaiseCallbackEvent, GetCallbackResult
in that interface call the javascript to that perticular method.
Please realise that this way you're not calling anything from the client (using javascript). This call will render 'functionname' on the server and return the result back to the browser. if you really need javascript to call a c# method, do any of the above
[:P]
Hope this helps !
Rinze Cats
---------
please select 'mark as answer' if this post helped you!
ankushbhanot
Member
14 Points
7 Posts
how to call a c# function from javascript
Dec 24, 2007 06:25 AM|LINK
Hello Frnds,
I am in a big problem...and need to call a c-sharp function from javascript.
help!
XIII
All-Star
182708 Points
23464 Posts
ASPInsiders
Moderator
MVP
Re: how to call a c# function from javascript
Dec 24, 2007 09:18 AM|LINK
Hi,
and welcome to the ASP.NET forums.
What you could do is expose the C# functionality through a webservice and call it with the help of AJAX.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
e_screw
All-Star
19530 Points
3894 Posts
Re: how to call a c# function from javascript
Dec 24, 2007 09:23 AM|LINK
For example look at this article http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx
Thanks
Electronic Screw
Website||Blog||Dub@i.net
alladi.sai
Member
265 Points
38 Posts
Re: how to call a c# function from javascript
Dec 24, 2007 09:41 AM|LINK
Hi,
implement the ICallbackEventHandler in the page and derive the two Events which are RaiseCallbackEvent, GetCallbackResult in that interface call the javascript to that perticular method.
-----------------------------------------------------------------------------
Don't forget to click "Mark as Answer" on the post that helped you.
ankushbhanot
Member
14 Points
7 Posts
Re: how to call a c# function from javascript
Dec 24, 2007 10:50 AM|LINK
ok guys, I have got the solution
I used <%=functionname()%>.
thanks
Rinze
Contributor
2580 Points
480 Posts
Re: how to call a c# function from javascript
Dec 24, 2007 01:06 PM|LINK
hehehe.
Please realise that this way you're not calling anything from the client (using javascript). This call will render 'functionname' on the server and return the result back to the browser. if you really need javascript to call a c# method, do any of the above [:P]
Rinze Cats
---------
please select 'mark as answer' if this post helped you!
ankushbhanot
Member
14 Points
7 Posts
Re: how to call a c# function from javascript
Jan 05, 2008 10:09 AM|LINK
you are right I didn't get the exact solution as it will just render the function at server side.
Now can you please give me any example for this.[:)]
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: how to call a c# function from javascript
Jan 05, 2008 10:47 AM|LINK
There are 2 ways to execute a server-side function from a client-side function:
1. Use AJAX.
2. Do a PostBack
aspx file:
<script type="text/javascript">
<!--
function callServersideMethod(valueToSend)
{
__doPostBack('callServersideMethod', valueToSend);
}
// -->
</script>
aspx.cs file:
private void Page_Load(object sender, System.EventArgs e)
{
// Insure that the __doPostBack() JavaScript method is created...
this.GetPostBackEventReference(this, string.Empty);
if ( this.IsPostBack )
{
string eventTarget = (this.Request["__EVENTTARGET"] == null) ?
string.Empty : this.Request["__EVENTTARGET"];
string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ?
string.Empty : this.Request["__EVENTARGUMENT"];
if ( eventTarget == "callServersideMethod" )
callYourServersideMethodHere(eventArgument);
}
}
The AJAX solution would be far too complex for me to post here. I suggest that you Google AJAX for more info on that.
NC...