Recently, I have been working on a Telephone Dialing system. The system is not big, but it takes a long time. One technology is used: js calls the background method. It took a lot of time to solve this problem, and I still have some questions to understand. I will share with you today. If you really understand it, please refer to SyntaxHighlighter. all (). Recently, we have been working on a dialing system. The system is not big, but it takes a long time. One technology is used: js calls the background method. It took a lot of time to solve this problem, and I still have some questions to understand. I will share with you today. If you really understand it, please correct me. In fact, in vs, this front-end call background method is still very common, but it is encapsulated by. We drag a button on the interface. After double-clicking the button, vs will automatically call the Click Event of the button on the foreground, and generate the Click method of the button in the background. In other words, we don't need vs to do this for us. We can write it by ourselves. The method is also very simple: Create a button at the front end to write the called or processed content to button_click in the background; then, write a js function at the front end with the content of document. getElementById ("btn1 "). click (); finally, call the js function at the front or back end to stimulate the click event, which is equal to accessing the c # function in the background. We encountered not the above situation, but similar to the following method: Background method: [csharp] public string javasecall (string strNum) {strNum = "James" + strNum; return strNum;} public string javasecall (string strNum) {strNum = "James" + strNum; return strNum;} front-end js method: [html] function Init () {var v = "Incoming call"; var s = '<% = receiveCall ("' + v + '") %>'; alert (s);} function Init () {var v = "Incoming call"; var s = '<% = receiveCall ("' + v + '") %>'; alert (s );} then you can call it at the front-end. When I first wrote this method, the program always went wrong. The frontend writes the method for calling the backend in the js method, but does not call it. As a result, it will still be executed. Sometimes the error is even a bit confusing. It cannot be called later. After searching for a long time on the Internet, I saw many people write the background method as protected. Then I did it and changed the background method in the Demo to the protected type. The program was OK, no such problems have occurred. Then I thought I found the answer, but the problem in the system is still not solved. In the telephone system, the background method is not called, but the method is called by yourself. This situation is extremely unstable. In some cases, invocation is not performed, and in some cases, invocation is not performed. Our solution to this problem is to remove the uncalled execution part and use the AJAX method in vs to implement it. (as mentioned in niuyun, it has never been used. I am going to introduce it to you in the next blog ). This seems to have been solved, but a new problem has emerged. Take a look at the following picture: the problem arises: Whenever you move your cursor to [Contact Me] in the figure, the phone numbers displayed in the pop-up box are the same. That is to say, when you transfer the phone number to another [Contact Me], the phone number in the pop-up box is the same as once. After the analysis, the following conclusions are drawn: 1. the information displayed in the pop-up box is normal when no backend method is called using js. This problem occurs after the backend method is called using js; 2. The information displayed in the pop-up box is also regular. The displayed value is the default value bound to the background. That is to say, the problem mentioned above has not been solved. In the js method, the backend method is secretly executed without being called. Even though the code is written with dynamic binding, the execution background method is like a constant, only default binding is executed for each call. Once the problem is analyzed, it will soon end. In fact, this problem occurs due to the page loading principle. Because js runs on the client, after the html page is loaded, the js Code will still be loaded. When it is loaded to the back-end method called, it will call the back-end method, the above problem occurs. The test also proves that <% = javasecall () %> is calculated when the page is bound. Add a breakpoint for debugging. The result is that the value of <% = javasecall () %> is calculated only when the page is refreshed. If you want to use this method when executing a function during page refresh, that is to say, you can use autopostback. Here, this is an extra step. In addition, when the js interpretation is executed, <% = javasecall () %> has been assigned a value, which can be considered as a constant. Therefore, the value of this value is not as expected to be triggered before the background event is executed. Now the problem has been clearly described. As mentioned above, the call method similar to <% = javasecall () %> is actually not an error. To use it correctly, you need to understand the page loading principle and be able to tolerate the conversion of the execution background method into a constant, so you can use it. This article briefly introduces and explains how to call the background method through js in the project. In some cases, I do not quite understand what I have said. I hope you can make an axe.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service