Differences between ASP. NET page and response output JS

Source: Internet
Author: User

After the submission is successful, the alert dialog box is displayed, using page. clientscript. registerclientscriptblock and direct response. write ("<SCRIPT type = 'text/JavaScript '>" + script + "</SCRIPT> ");

The alert content is displayed. However, the style of the page is changed by using the response method. Unexpected page disorder occurs. The cause is unknown.

Below is a JS group class

   Public   Class  Jshelper {  Public   Static  Httpresponse response {  Get { Return Httpcontext. Current. response ;}}  ///   <Summary>          ///  This method will inexplicably lose the style if the page has a server text box Control  ///   </Summary>          ///   <Param name = "script"> </param>          Public   Static   Void Executescript ( String  Script) {response. Write ( "  <SCRIPT type = 'text/JavaScript '>  " + Script + "  </SCRIPT>  "  );}  ///   <Summary>          ///  This method can achieve the expected alert effect without changing the style  ///   </Summary>          ///   <Param name = "script"> </param>         ///   <Param name = "page"> </param>          Public   Static   Void Executescript ( String  Script, page) {page. clientscript. registerclientscriptblock (  Typeof (Page ), "  MSG  " , "  <SCRIPT type = 'text/JavaScript '>  " + Script + "  </SCRIPT>  " , False  );}  Public   Static   Void Gotourl ( String  URL) {response. Write (  "  <SCRIPT type = 'text/JavaScript '> top. Location. href ='  " + URL + " '; </SCRIPT>  "  );}} 

1. UsePublic Static VoidExecutescript (StringScript) method:

 
2. UsePublic Static VoidExecutescript (StringScript, page)Method:

The second is normal. The style of the text box is not deformed.

 
 

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.