Ever tried making a Utility method to create a script to be registered with the page in ASP.NET that will popup a JS alert box and takes a message? Ever see what happens when you try and place a single quote in the value like "The value 'x' is not allowed"? The JS will error out on the page with a " Expected ')' " type error message. If you use the utility mentioned above, the encoding is done for you and injects any needed escape characters. The line of code below shows how this might be done in .NET code:
Dim Message As String = "The value 'x' is not allowed"
'URL Encode the message prior to registering with the page
ClientScript.RegisterStartupScript(Page.GetType(), "AlertJsFunction", JsAlert)