In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "example analysis of the interaction between javascript and background c # in asp.net". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "example analysis of the interaction between javascript and background c # in asp.net".
There are four main aspects in the intercall between C # code and javaScript function:
1. How do I access C # functions in JavaScript?
two。 How do I access C# variables in JavaScript?
3. How to access the existing variables of JavaScript in C #?
4. How to access the JavaScript function in C #?
1. Execute the function in the C# code in the javaScript function:
Method 1: combine page with page class
1. The function is declared as public
Background code (you can also change public to protected)
Public string ss () {return ("a");}
2. Use the name of the function that can be called / / in the background of C# in html
Foreground script
Var a = ""; / / call the C# background function alert (a) in JavaScript
Method 2: JavaScript asynchronously calls the method defined in the ASP.Net page
1. Declare the method as public
two。 Declare the method as a class method (Shared in static,VB.NET in C #), not an instance method
3. Add the method to the [WebMethod] attribute
4. Set the EnablePageMethods property of the ScriptManager control on the page to true
5. Call the page method on the client using the following JavaScript syntax
PageMethods. [MethodName] (param1,param2,...,callbackFunction)
6. Specify the callback function for the client asynchronous call, accept the return value in the callback function and further process
7. Add using System.Web.Services
Example:
Foreground JavaScript code
Untitled page function JsCallCSharp (param1) {PageMethods.sayhell (param1,onSayHelloSucceeded); / / sayhell is the method marked with the [webMethod] attribute in the background param1 is the parameter passed into the method, onSayHelloSucceeded is the callback function, which is mainly used to further deal with the results returned by the background} function onSayHelloSucceeded (result) / / bound callback function {alert (result);} / / ScriptManager control manages scripts, pay attention to setting EnablePageMethods= "true" this property
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.