RegisterStartupScript Object Advantage

The main concept of this article is, a window's like message box for Web.

The general practice by developers to show a message box by using the script tag along with alert in the Response.Write, like Response.Write("s c r 1 p t > a1ert('hi') / s c r 1 p t"). The main disadvantage of this kind of code is, the page will stop rendering till the user presses "OK" button, during which the background will be white and nothing will be visible. This could cause the client see nothing untill "OK" key is pressed.

One can change this behaviour with RegisterStartupStript object. The explanation from MSDN on this object is, this method emits the script just before the closing tag of the Page object's <> element..

What you benifit out of this? and how can you implement this?

The benifit is, the user can see the page and as well the message window. And you can make use of this object with the following example



StringBuilder strMsg = new StringBuilder();
strMsg.Append("<. $cr");
strMsg.Append("1pt language=J@va$cr1pt id='OpenDocument'>");
strMsg.Append("alert(' ");
strMsg.Append(strMssg);
strMsg.Append(" ');strMsg.Append("$cr");
strMsg.Append(".1pt>");
this.RegisterStartupScript("Alert",strMsg.ToString());String());

Hope this code will help you, it worked for me.

Comments

Popular posts from this blog

Network Intrusion Detection using Supervised ML technique

Common mistakes by Interviewer

Keep the system active, to avoid the auto lock