[Daily] Asp.net response. Write

Source: Internet
Author: User
1. directly use response. when the write () method is used to output alert or other JS Code , some page styles are affected

Because response. before the write method outputs the <SCRIPT> label to the <doctype> label, the <doctype> label is ignored, as a result, the browser interprets the page as a bunch of tags rather than a valid HTML document. The page rendering mode is changed to the quirks mode) instead of the standard compatible mode (Standards Compliance mode), this affects the interpretation of HTML and CSS, because the browser attempts to imitate a comparative version of it, it will produce a lot of weird and wrong. In addition, he will use different default styles for the elements, which leads to final style problems.

The following is an important sentence:<Doctype> anything before the label will cause the <doctype> label to be ignored.

Method 1: Replace the response. Write () statement with this

Page. registerstartupscript ("servicemanhistorybuttonclick", "<SCRIPT> window. Open ('equipmenthistory. aspx? Eid = "+ servicemandropdownlist. selectedvalue +" '); </SCRIPT> ");

This method is used to issue a client script block in the page response. The previous parameter is the unique name of the script in the page (you can start it without repeating it), and the other is the script content.

This method should be officially recommended by Microsoft.

Method 2: originalProgramThe response. Write () Statement

Response. Write ("<SCRIPT> document. Location = Document. Location; </SCRIPT> ");

2,Microsoft Ajax technology is used in ASP. NET to export the Excel file in updatepanel. Http://topic.csdn.net/u/20080412/14/502aaafd-609c-4063-bc5f-ee91cc9140a2.html Solution: <Asp: scriptmanager id = "scriptmanager1" runat = "server" enablescriptglobalization = "true" enablescriptlocalization = "true"> </ASP: scriptmanager>
<Asp: updatepanel id = "updatepanel1" runat = "server">
<Contenttemplate>
<Br/>
Your own HTML code...
<Asp: gridview id = "gridview1" runat = "server">
</ASP: gridview>
<Asp: linkbutton id = "lbtnexport2excel" runat = "server" onclick = "lbtnexport2excel_click"> export Excel </ASP: linkbutton>
</Contenttemplate>
<Triggers>
<Asp: postbacktrigger controlid = "lbtnexport2excel"/>
</Triggers>
</ASP: updatepanel> 3. Rewrite verifyrenderinginserverform method http://blog.csdn.net/JeromeLvye/article/details/5250701 if an exception occurs, code scheduling directly enters the Catch Block, the custom output code will not execute context. response. write (SW. tostring (), and the system outputs the entire page. All the unnecessary controls are exported. Publish via wiz

Related Article

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.