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

Source: Internet
Author: User

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.

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.