954,180 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Calling C# function through Javascript in ASP.NET

Hi Guys,

Is it possible to call the C# function from Javasript......

Sushil Kumar :rolleyes:

SushilKumar
Newbie Poster
1 post since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

Not directly, no. Server-side functions live server-side, client-side functions live on the client.

In fact, the only way to get ANY server-side code to run, is to submit the form. ASP.NET unrolls the HTTP headers, unpackages the hidden ViewState variable, re-instantiates objects, and then decides what events to raise based on all of the above.

What you can do is have your JavaScript function set a hidden form variable, then do a form.submit().

Then, in your Page_Load handler on the server, use the Request object to check for the presence and/or value of this variable, and call the appropriate server-side method.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Hi Guys,

Is it possible to call the C# function from Javasript......

Sushil Kumar :rolleyes:

Yes it is possible to call C# function through javascript using Ajax extensions in Asp.Net

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

You're a little late serk.. :)

Aug 24th, 2005

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 
farrukhiftikhar
Newbie Poster
1 post since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Just a quick thought here. Vfp programmer learning C#, .net, etc. Even with the time differences on the post I found it really helpfull on my learning curve. Thanks guys!!!
Oct 27, 3009!

binbotboo
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 
carobee
Posting Whiz in Training
209 posts since Dec 2007
Reputation Points: 10
Solved Threads: 12
 
Just a quick thought here. Vfp programmer learning C#, .net, etc. Even with the time differences on the post I found it really helpfull on my learning curve. Thanks guys!!! Oct 27, 3009!


Attention Dani ! We have got an alien from future in this board.

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

my ID :yasu_6in@yahoo.co.in

without using javascript how to call a server side in function in textbox onblur event

ex:

public void disp()
{
Response.Write("Hi");
}

page_Load()
{
TextBox1.Attributes.Add("onblur","disp()");
}

its not working

how to call this function

without using javascript or any other scripts

similarly i need concept from textbox blur event , not any button events

plz help me to get a code ..

Thanking You

nimsayunab
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 
Minal Patel
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

You should use web service or wcf (axaj)
send method to web service than shuld run to "this.GetType().InvokeMember" for the method

i am using , very good tecnology same windows application,

halilcorak
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

JavaScript can not talk with serverside methods since the client is on the Earth and the server is the Moon. You need to use a spaceship to get there. So you need to either postback the page or look into using Ajax.

visit http://weblogs.asp.net/mschwarz/archive/2005/02/15/373072.aspx

source >> http://forums.asp.net/t/1184597.aspx

kouroshnik
Light Poster
33 posts since May 2010
Reputation Points: 14
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You