Call c# function from javascript function

This is my code:

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%

@ Import Namespace="System.Web.Services" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title>Untitled Page</title>

<script runat= server>

[

WebMethod]

public string GetName()

{

return "Hello Word";

}

</script>

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

function btnCercaClick()

{

 

var value = GetName(success);

alert(value);

}

 

function success(result)

{

 

}

</script>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">

</asp:ScriptManager>

<asp:Panel ID="pnlRicercaCliente" runat="server" Width="100%">

<h3>

Find Cliente:

</h3>

<p style="vertical-align: middle">

<input id="txtRicerca" type="text" />

<input id="btnCerca" type="button" value="button" onclick="btnCercaClick()" /></p>

</asp:Panel>

</div>

</form>

</

body>

</

html>

 

This is a simple fragment of code, but there is an error.

Why??

Thanks.

0
SuperPostIt
3/12/2007 2:51:33 PM
asp.net.ajax-discussion 13973 articles. 1 followers. Follow

2 Replies
1596 Views

Similar Articles

[PageSpeed] 24

How do want to call server code from client code?

If you look at the web source, you will see the server code does not appears
Hello everybody
0
Amethyste
3/12/2007 3:39:15 PM

The method you're calling (GetName) should be marked static, and then you should call it with PageMethods.GetName(success).

See the example at the bottom of http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx.


Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
0
Steve
3/12/2007 3:52:32 PM
Reply:

Similar Artilces:

calling a javascript function from a c# function
Hi,I'm using asp.net, c# framwork 1.1 and some javascript.I have a table in which there are 3 cells.In each cell there is a control.In the first cell the control ID is DropDownList1 and the items are Item1, Item2 and Item3.In the second cell, the control ID is TextBox2.In the third cell, the control ID is TextBox3.What i am trying to do is :If DropDownList1 selected value equal Item1   then hide the second AND the third cells.If DropDownList1 selected value equal Item2   then show the second cell AND hide the third cell.If DropDownL...

calling c# function in javascript function
I'm trying to call a c# function in my javascript function that I use as a buttons OnClientClick. The c# function simply changes some session variable values. The problem I'm having is that everytime my page posts back the c# function that is called within my javascript function is executing, and the only time it should execute is when the button is pressed. I'm not sure what I'm doing wrong but heres my code: <script type="text/javascript"> function Go() { <%SetDefault(); %> window.open('https://portal.cityofmoorhead.com/timecard/timecard.aspx','mywindow4','scrollbars=yes,l...

want to call a function of c#.net from javascript
hi everyone. i want to call a function of c#.net from javascript. and i also want to pass an argument from javascript to  that function. can anyone help me? thanks in advance. shweta  ThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path Can you be more precise about the effect you're trying to achieve?  Explain you requirements , what you want to achieve be thisIf this post helps you, please mark it as Answer.Cheers,Muhammad Rizwan JavedSr .Net DeveloperAim 168, Dubai, UAE. Hi Try this, U'r Codeb...

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

How to javascript function from C# function ?
i have a popup function in the javascript. when ever i call it from HTML controls's onClick event it is working well. but when ever i writeResponse.Write("<script>"); Response.Write("PopupPicker(215,200);"); Response.Write("</script>"); in c# method it doesn't work any thing.my javascript function is as follow:<script language="javascript"> function PopupPicker(w,h) { var PopupWindow=null,settings; settings='width='+ w + ',height='+ h + ',location=no,directories=no,men...

calling a javascript OR C#.net function from XSLT file
Hi, Is there a possiblilty of calling a javascript function, from within xslt file.  For example something like this:- <xsl: if test="projectfile [.!=' ']"><a class = "links"><xsl:attribute name="href"> helloworld:</xsl: attribute> BrowseFiles</br></a><xsl:if> Where in the above code "helloworld" is the name of the java script function, that displays a text message. Please, tell if this is possible to do so, or refre me to a good resource. Thanks,   Hi srinivasc_it, It seems as if you...

How to call server side function by javascript using Ajax.Net
Sir, I want to call the server side function by javascript function. Is it possible using Ajax.Net (System.Web.Extensions.dll or AjaxControlToolkit.dll)? If yes then please give me the code or URL. I found some article using Ajax.dll but I want to use System.Web.Extensions.dll or AjaxControlToolkit.dll. Please help me. Thanks in advance Paresh        Hi, Ajax.NET and ASP.NET AJAX, what you want, are completely different implementations so please be sure to use the correct terminology in the future as there are already 100+ AJAX frameworks aroun...

Call JavaScript functions from C/C++ in SpiderMonkey
Hi, I am new to spidermonkey and I want to know if it is possible to load javascript code to spidermonkey in an application of mine and execute only some functions from it using C/C++. I have managed to embed spidermonkey in my application and compile & run javascript code but I cannot find anything on how to call a function from it. Allthough I have found enough info on how to make available C++ functions and classes to javascript code the only reference I have found on the opposite is the following: ----------------------------------------------------------------- H...

Data transfer from a C++ calling function to Pascal called function [Edit]
Hello, In a C++Builder 2010 project I have a function calling another function in a pascal unit. This pascal unit is included in my project. The problem I cannot solve is that the one of the parameters in the calling function is not transferred correctly to the called function. Calling C++ function: {code} ID3v2Tag->SetUnicodeComment("COMM", FComment, FLanguageID, FDescription); {code} Declarations: {code} TID3v2Tag *ID3v2Tag; // type defined in pascal unit TLanguageID FLanguageID; // type defined in pascal unit String FComment; ...

Call javascript function from a server function
Hi, I have as server button on the page and onclick i am calling a server function (check()) In between the function how to call the javascript function <script runat=server> Function check() Some code here ************* CALL JAVASCRIPT FUNCTION HERE************ End Function </script> Can any one help me please Thanks Why do you need to call the javascript. Can't you implement javascript's logic in your language(VB)? Also, javascript can be server or client side. Problem is, you cannot use both Javascript and VB as the server script so you...

Call javascript function from VB function?
Can I call a javascript function from inside a VB function/sub? I would like to call a javascript function that refreshes the parent page after a record has been inserted into a database. I have the javascript function I just dont know how to call it from a vb function/sub?  Any help would be awsome  You can't call client methods from server code, only the other way around. Unless your insert is a very long operation, the best idea is just to do the insert as normal. i.e. perform the insert on postback, then allow the page markup to render as normal.My Blog   captai...

Can I call a javascript function in C# or VB.NET without triggering any events?
Hi, I have a javascript function <script language="javascript"> function dblTotalPrice(intQuantity, dblRoundNumber, intUnitPrice) { return intQuantity*(Math.round(dblRoundNumber+intUnitPrice/2.0)+7); } </script> in WebForm1.aspx file. I want to call this function in a C# or VB.NET function which is in code-behind file WebForm1.aspx.cs or WebForm1.asp.vb, but I don't want involve any events when I call this javascript function. Can I do this way? Thanks! You can not call. If you insist on calling, you should emit some client...

How to call javscript function from a C# function
Hi All, I am writing a FileBrowser Utility for my company. So far so good. The feature copy/paste and cut/paste requires me to show a confirm box to say if a file needs to be overwritten. I have done all the coding using C# for cut/copy and paste. Its working fine now, and instead of asking the user for overwriting a file i create a [copy() <file name>  as used by windows explorer] file now. I just need some way so that when i paste 10 files a confirm box to be shown whenever a file with the same name is encountered. Hope this can be achived using javascript, but i am afraid...

call a server side function from javascript function
hello i have apage that is contained in MasterPage (contents) i have a HyperLink and i want to call a serverside function is it possible? i am writing C# nirnironIf i helped you please mark as answered.. in your page_load event, you can reference controls on the masterpage by MasterPage.FindControl("....")  Peter Kellnerhttp://73rdstreet.com and blogging athttp://PeterKellner.netMVP, ASP.NET  Use the "LinkButton" control...  Looks the same as a hyperlink, acts the same, and you can catch events from it. no... ok this is the scenario... i have ...

Web resources about - Call c# function from javascript function - asp.net.ajax-discussion

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

Quickstart: Facebook SDK for JavaScript
This quickstart will show you how to setup the SDK, load social plugins, trigger a dialog, and get it to make some basic Graph API calls.

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 1/14/2016 8:57:04 PM