The problem that the page font becomes larger due to response using response. Write () in ASP. NET

Source: Internet
Author: User

For example, there is a LinkButton in the page. You need to click it to open a new window, And the URL of the new window is generated dynamically based on the user selection result. Write the LinkButton Code as follows:
Protected void ServiceManHistoryButton_Click (object sender, EventArgs e)
{
Response. Write ("<script> window. open ('equipmenthistory. aspx? Eid = "+ ServiceManDropDownList. SelectedValue +" '); </script> ");
}
After running, you will find that the new window is opened, but the font of the original page has become larger, which is a strange problem!
Some people want to say that CSS is not set up, and I am speechless to these people. I am most afraid to meet them when I ask for advice.
The actual cause is that the script code is output directly to the top by Response. write, which breaks down the document model and causes such a result.

OK. There are two solutions.

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:Add a sentence after the Response. Write () Statement of the original program

Response. Write ("<script> document. location = document. location; </script> ");

It's really high to come up with this solution!

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.