<VB.NET>
-------------------
Catch ex As Exception
Me.RadAjaxPanel1.ResponseScripts.Add("radalert('" & ex.Message & "')") '' < Doesn't work>
Me.RadAjaxPanel1.ResponseScripts.Add("radalert('A error occurred. ')") '' < Works >
End Try
I want the radalert to dynamically display the text of the error message in the dialog box. I dont want to have static text. What am I doing wrong?
4 Answers, 1 is accepted
Did you include a RadWindowManager on the page?
The declarations should look like this:
<
telerik:RadWindowManager
ID
=
"WindowManager1"
runat
=
"server"
></
telerik:RadWindowManager
>
<
telerik:RadAjaxPanel
runat
=
"server"
ID
=
"RadAjaxPanel1"
>
<
asp:Button
Text
=
"Get Response"
ID
=
"btn1"
OnClick
=
"btn1_Click"
runat
=
"server"
/>
</
telerik:RadAjaxPanel
>
And in the code-behind:
protected
void
btn1_Click(
object
sender, EventArgs e)
{
string
someValue=
"Something"
;
RadAjaxPanel1.ResponseScripts.Add(
"radalert('"
+ someValue +
"')"
);
}
Best wishes,
Genti
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

The client error handling should be implemented through the scriptmanager instance.
In order to do so you have to make the following changes.
1) Define a AsyncPosbackError handler:
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
OnAsyncPostBackError
=
"ScriptManager1_AsyncPostBackError"
>
protected
void
ScriptManager1_AsyncPostBackError(
object
sender, AsyncPostBackErrorEventArgs e)
{
RadScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message;
}
2) Then in order to get the response from the ScriptManager on the client you can do the following(JavaScript):
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function
EndRequestHandler(sender, args) {
if
(args.get_error() != undefined && args.get_error().httpStatusCode ==
'500'
) {
var
errorMessage = args.get_error().message
args.set_errorHandled(
true
);
radalert(errorMessage);
}
}
I am also attaching a simple project that illustrates this.
Best wishes,
Genti
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Solution.
You suggestions helped in finding the problem, but the basic problem was this: The radalert text argument can not have a value with either character returns or line breaks in them. Basically, what happen was, the exception.message value had a line break in the value. This was apparent when, during troubleshooting, I used the msgbox in the code behind to display the error message (see attachment). I created a sub routine to change the characters to thier equivalent ASC value. When I did that, I saw 10 and 13 which are line feeds and character return codes. The sub routine removes those codes, and when I used the returned value from my sub in the radalert function everything worked.
Public
Function
RemoveLineBreaks(
ByVal
text
As
String
)
As
String
Dim
Length
As
Integer
= Len(text)
Dim
i
As
Integer
= 1
Dim
Asc
As
String
Dim
AscStringBuilder
As
New
StringBuilder
Dim
AscString
As
String
Dim
AscArray()
As
String
Dim
TextBuilder
As
New
StringBuilder
'Convert to ASC String
AscStringBuilder.Append(
"-"
)
Do
Until
i > Length
Asc = Strings.Asc(Strings.GetChar(text, i).ToString)
AscStringBuilder.Append(Asc &
"-"
)
i = i + 1
Loop
'Replace LineBreak codes
AscString = Replace(Replace(AscStringBuilder.ToString,
"-10-"
,
"-"
),
"-13-"
,
"-"
)
'Convert back to text
AscArray = Split(AscString,
"-"
)
For
Each
AscNumber
In
AscArray
If
IsNumeric(AscNumber)
Then
TextBuilder.Append(Strings.Chr(AscNumber).ToString)
End
If
Next
Return
TextBuilder.ToString()
End
Function
End
Module