ASP.NET: How is the flow of control when JavaScript is called from code behind?
-
Recently I called a JavaScript from code behind using page.registerstartupscript. Now as javascript is executed on client machine and code behind would run on server. Does server continue executing .cs code? or does it wait until javascript is finishes its execution? If it waits then how does it get knowledge of completion of executed script?
-
Answer:
MSDN, .Net Framework 4 ClientScriptManager.RegisterStartupScript Method (Type, String, String) http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script. Call the IsStartupScriptRegistered method to determine whether a startup script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script. In this overload of the RegisterStartupScript method, you must make sure that the script provided in the script parameter is wrapped with a <script> element block. The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised. The script blocks are not guaranteed to be output in the order they are registered. If the order of the script blocks is important, use a StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block. In short: the method does not execute any Javascript, it simply adds a script block to the output of the control that renders right at the bottom and is run on the client-side. The code in the .cs file tells the compiler to add the defined Javascript to the output, nothing more.
Ronald Ng at Quora Visit the source
Related Q & A:
- How can I allow user to create posts in website using ASP.NET?Best solution by Programmers
- How to Undo previous action in asp.net?Best solution by forums.asp.net
- How to Search using jQuery ASP.Net?Best solution by Stack Overflow
- How to Play Audio files in ASP.NET?Best solution by Stack Overflow
- How to save high resolution image canvas to server using asp.net?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.