This is a migrated thread and some comments may be shown as answers.

Unterminated string constant error when calling rad alert

1 Answer 317 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 06 Oct 2011, 04:52 AM
Hi,

I am getting am getting the error "unterminated string constant" when I try to call a rad alert from code behind.  I know the problem is that the message that is being sent to the radalert contains invalid characters but I am not sure how to fix it. 

I am calling the radalert on a grid's ItemUpdated event and am putting the e.exception.message in the string that I pass to the radalert and apparanetly it has invalid characters.   Since I can't control what the characters are in the e.exception.message, is there a way to send this information to a radalert so that it will accept the e.exception.message.

The e.exception message is
Incorrect syntax near ','.
Unclosed quotation mark after the character string ".

Below is the code I am using to call the radalert.
Protected Sub rgvSecurityUsers_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles rgvSecurityUsers.ItemUpdated
    If Not e.Exception Is Nothing Then
        Dim EditItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim strUserId As String = EditItem.GetDataKeyValue("UserID").ToString()
        Dim strUserName As String = TryCast(EditItem("UserName").Controls(0), TextBox).Text
        Dim strMessage As String = "User " + strUserId + " " & strUserName & " cannot be updated. Reason: " + e.Exception.Message
        MsgBox(e.Exception.Message)
        Dim scriptstring As String = "radalert('" + strMessage + "', 330, 210);"
        e.KeepInEditMode = True
        e.ExceptionHandled = True
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)
    End If
End Sub

Thank You
Tracy
.

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 07 Oct 2011, 03:06 PM
Hello Tracy,

  Such an error is usually thrown when there is an apostrophe in the string, so you need to properly escape this string so that JavaScript can work with it. Keep in mind that the RadAlert accepts an HTML string, so you can use entities, for example:
Dim msg As String = "test apostrohpe ' other text"
msg = msg.Replace("'", "& #39;")
rwm1.RadAlert(msg, 400, 200, "title", Nothing)

NOTE: you need to remove the empty space after the ampersand, as otherwise the browser will turn the entity into the actual sign.

Other symbols can be escaped in a similar manner. Please note that we cannot foresee all possible combinations and the RadAlert therefore does not modify the string you pass to it. Providing proper strings to the application is the developer's responsibility. I cannot be certain of all the possible special characters, yet I believe the following google search may be useful in researching the matter: http://www.google.com/search?q=special+characters+in+VB.

Greetings,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
General Discussions
Asked by
Tracy
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or