This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13118|Reply: 0

[ASP.NET] Three ways to output js ASP.NET background (write for beginners)

[Copy link]
Posted on 7/21/2015 10:27:04 PM | | |
ASP.NET provides three ways to output JS in the background:
1. There is already a js file in the background output
Start by creating a js file testjs.js

if (! Page.Clientscrip removes t.IsClientscrip removes tIncludeRegistered(this. GetType(), "keys"))) // to determine if the keys are registered
{
   Page.Clientscrip removes t.RegisterClientscrip removes tInclude("keys", "testjs.js");     
}
2. Output the js code block
string scrip remove tstrs = ""; This is for demonstration only, if the code needs to be spliced multiple times, the StringBuilder method should be used
scrip removes tstrs += "function test(str)";
scrip remove tstrs+="{alert(str); }";
if (! Page.Clientscrip removes t.IsClientscrip removes tBlockRegistered(this. GetType(), "keys"))
{
     Page.Clientscrip removed t.RegisterClientscrip removed tBlock(this. GetType(), "keys", scrip remove tstrs, true);
}
3. Output the disposable js code

        string scrip remove tstrs = "<scrip去掉t>alert('Welcome!' ); </scrip去掉t>";
        if (! Page.Clientscrip removes t.IsStartupscrip removes tRegistered(this. GetType(),"welcome"))
        {
            Page.Clientscrip removed t.RegisterStartupscrip removed t(this. GetType(), "welcome", scrip remove tstrs);
        }
In addition, use Response.Write("<scrip去掉t>alert('ww'); </scrip去掉t>"); You can also output simple js code, but I personally don't advocate this method. Because in the previous development, there were some cases where this method would cause the page font size to change after the prompt message pops up, so it is recommended to use the above three methods for safety reasons.





Previous:How to implement the pop-up frame with js?
Next:The computer card in Wuhan Houpu computer room cannot be used at all
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com