Little tips for using JavaScript in ASP.NET

xiaoxiao2021-03-05  22

We often use some JavaS cript scripts when conducting ASP.NET development, such as Private Void Button1_Click (Object Sender, System.EventArgs E) {response.write (" Alert) 'Ok'); ");} It is often written for repeated writing. If we can make a corresponding function, you can use it directly. Many people have some of their own JavaS Cript functions, but most of them are such: ///

/// server-side pop-up Alert dialog / // /// /// Page class public void alert (String Str_Message, Page Page) {ix (! Page .Isstartupscriptregistered ("msgonlylert")) {page.registerstartupScript ("msgonlylert", " Alert ('" str_message "); ");}}, but when used, each time To inherit this class, it is still a bit trouble. If the function is a static function, the class is a static class, we can use it if we are inherited. But what do we write? Take a look at this code #Region Public Static Void MessageBox (Page Page, String Msg) / / / / / / / Bounce Dialog / / / / / The pointer of the current page is generally this /// message public static void MessageBox Page Page, String MSG) {StringBuilder strscript = new stringbuilder (); strscript.Append ("); strscript.append (" Alert ('" msg "); "); STRScript.Append (""); if (! Page.isstartupscriptregistered ("MessageBox")) {page.registerStartupScript ("MessageBox", strscript.tostring ());}} #ENDREGION This kind of Convenient to use a lot of JS scripts. PS: Actually, many common methods can be written in a static function. There are even more examples there to be given as a reference.

转载请注明原文地址:https://www.9cbs.com/read-36145.html

New Post(0)