简体   繁体   中英

RegisterStartupScript alert message messing up html/css

I've got an ASP.NET application, which calls this code at some point, to display an error message:

ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Incorrect login details.')", true);

For some reason or other, when this alert box is displayed, my webpage's layout is changed and some elements are not in their correct places.

Is there any way that this may be avoided?

When the response is written, it's immediately starts executing it and that's why probably your HTML is messed.

Try to alert after the page is loaded.

You can achieve this easily using jQuery.

ClientScript.RegisterStartupScript(this.GetType(), 
                  "", 
                  "$(document).ready(function(){alert('Incorrect login details.')});",
                  true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM