Use VB6 or VB. NET developers will always use the msgbox function to display messages. net in the Development of ASP. net program, you will find that the msgbox function seems to be usable, And you will directly use msgbox to display messages.
Msgbox ("this is a message ")
In the vs development environment, the msgbox function can display messages normally. However, once the website is released, the msgbox function becomes invalid. Why? Msgbox is a servo language, and the client can only parse HTML and JavaScript through a browser. Therefore, msgbox functions cannot be used in ASP. NET programs and can only be used for debugging. In ASP. NET, the correct way to display messages on the client is to use the registerstartupscript method to output the alert function of JavaScript.
Scriptmanager. registerstartupscript (Me, me. GetType (), "alert", "alert ('this is message')", true)
Or
Me. clientscript. registerstartupscript (Me. GetType (), "alert", "alert ('this is message')", true)
Is it too much trouble to display messages in ASP. NET? Can you use msgbox to display messages in ASP. NET? In fact, the method is very simple, just write a msgbox method by yourself, and you can extend the msgbox you used to display messages. We wrote the msgbox method in basepage. This msgbox method also processes the section of the message body containing "single quotes" and "line breaks" and converts these special strings into corresponding JavaScript escape characters.
''' <Summary>
''' Prompt message is displayed.
''' </Summary>
''' <Param name = "message"> message body. </Param>
Public sub msgbox (byval message as string)
Dim sscript as string
Dim smessage as string
Smessage = strings. Replace (message, "'", "\'") 'process single quotes
Smessage = strings. Replace (smessage, vbnewline, "\ n ")'
Sscript = string. Format ("alert ('{0}');", smessage)
Scriptmanager. registerstartupscript (Me, me. GetType (), "alert", sscript, true)
End sub
All pages that inherit the basepage can use the msgbox method to display messages.
Protected sub button#click (byval sender as object, byval e as system. eventargs) handles button1.click
Dim smessage as string
Smessage = "alert message line feed test" & vbnewline & "test 'single quota '"
Msgbox (smessage)
End sub
Handler handler: processing the Javascript related function, attackers use the methods provided in the article "create your own scriptmanager to manage Terminal commands" to handle this problem, therefore, the msgbox method can be written into the tbscriptmanager class in this article.