tags:

views:

37

answers:

4

is it possible to call asp function inside java script function?

eg

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;


<script runat="server">

protected void btnSave_Click(object sender, EventArgs e)
{

}
</script>

<head>.....
</head>

script type="text/javascript" language="javascript">

     function abc() 

{  .
   .
   .
   .


 btnSave_Click( sender,  e);

}

This code is just to give you idea what kind of working i want. Thank you.

sangram Nandkhile.

+2  A: 

No, you would need to do a post back to the server to accomplish this.

consultutah
can u just gimme a small code to clear the concept ?
Sangram Nandkhile
A: 

In order to call server-side code from client-side code you'll need to post back to the server. Here's a quick result from Google on the subject:

http://www.dotnetspider.com/resources/1521-How-call-Postback-from-Javascript.aspx

David
ya ..but i need it in c#....actually... i m a beginner and this is my 1st assignment in asp dot net..so post back method is a bit difficult fr me..if u can mention a small code according to my sample code..so it will be easy for me ...thnk you
Sangram Nandkhile
+1  A: 

not directly. the javascript code is executed by the browser, ie on the computer of the visitor of your page, whereas the asp code is executed on the server. ways exist to mix the two - you might want to read up on AJAX (asynchronous javascript) which is basically all about getting the client-side to update based on server-side functionality without an actual reload.

Nicolas78
A: 

You could use javascript to call a web service (.asmx) on the server and return a result. It is easy to do and probably sounds more daunting than the actual work involved.

Take a look at "jQuery, AJAX, and ASMX" for a tutorial to get you started. It is easy to write a simple "Hello World" web service and it is definitely worth the effort to learn more about making AJAX calls to the server.

It's also worth looking at WCF. There are some good posts on SO to look at:

Alison