The discovery that the css style does not take effect after the. net page is submitted. The css style after the. net page is submitted
The problem that has not been solved for a long time has finally been solved by the teacher's prompt.
Problem: The asp.net page, after submission, or in the simplest example, when logging on to the page, an input error occurs and Response is used. write ("<script> alert ('user name or password error'); </script>. After the dialog box is displayed, the css style of this page will become invalid. It can be reflected in that your page is originally centered, but it becomes left aligned.
Solution: cancel the use of Response. Write ("<script> alert ('user name or password error'); </script>. Use
ClientScript. RegisterClientScriptBlock (this. GetType (), "msg", "alert ('username or password error')", true.
Summary principle:
Use response. write to output JS. Because the output will be earlier than the document style declaration, it will invalidate your CSS.
Extended Summary: RegisterStartupScript () is used to add the script block to run after the page is loaded. The script block added in this way is located at the end of the Web form, because the HTML elements to be modified must be defined before the script runs. That is, if you want to use a client script to set the focus to the text box, make sure that the HTML mark of the text box is before the script that sets the focus of the text box.
The RegisterClientScriptBlock () method is used for script code executed to respond to client events. The script block sent using this method is located at the beginning of the Web page, because this method does not require that the script block be placed after all HTML elements, that is, it generally does not use custom controls in the document.