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!