Try this. There are couple of error such as Not supported in C#: OnErrorStatement but you can write your own.
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.ComponentModel;
using System.Web.UI;
using Telerik.Web.UI;
//
// RadMsgBox - Copyright (c) 2009 - David Eisner
// note: this version handles both ajaxified and non-ajaxified controls
//
[DefaultProperty("ShowAlert"), Description("This control provides client-side modal dialog boxes utilizing the Telerik window system."), ToolboxData("<{0}:RadMsgBox runat=server></{0}:RadMsgBox>")]
public class RadMsgBox : System.Web.UI.WebControls.WebControl, IPostBackEventHandler
{
// this control utilizes the Telerik window manager and modal dialog windows to
// expose public methods that allow a developer to use modal dialogs from
// server code. due to the key structure utilized, multiple invocations of
// a single control can be used
//
// notes: This control requires Telerik script manager and window manager controls
// to be defined prior to use. This control should be declared in the Page_Load even
// of a page
//
protected static List<
string
> FunctionOutputArray = new List<
string
>();
private enum MsgType : int
{
AlertMsg = 1,
ConfirmMsg = 2,
PromptMsg = 3
}
//Here the key is kept to identify which event the message corresponds to
private string _Key;
//Option if Yes postback is desired
private bool _PostBackOnYes;
//Option if No postback is desired
private bool _PostBackOnNo;
//Option to determine postback for prompt
private bool _PostBackOnPrompt;
//value to hold which message type is being processed by the control
private MsgType _MsgType;
#region "Public Events"
//
// Declare the public events that can be dispatched by this control
//
public event YesSelectedEventHandler YesSelected;
public delegate void YesSelectedEventHandler(object sender, string Key);
public event NoSelectedEventHandler NoSelected;
public delegate void NoSelectedEventHandler(object sender, string Key);
public event PromptResponseEventHandler PromptResponse;
public delegate void PromptResponseEventHandler(object sender, string Key, string Value);
#endregion
#region "Public Methods"
//
// define the public methods that can be set for the control
//
public void SetConfirmation(string stConfirmationMessage, string stTargetControlID, string Key, bool PostBackOnYes, bool PostBackOnNo, int Width = 300, int Height = 100, string stTitle = "<
strong
>Confirm</
strong
>")
{
// this method exposes a passive way to bind a radconfirm() window to a control
// which will be launched on the client-side
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.ConfirmMsg;
// set for instance processing so the class understands what method it is rendering
if (stConfirmationMessage == string.Empty) {
return;
}
if (stTargetControlID == string.Empty) {
return;
}
if (Key == string.Empty) {
return;
}
// retrieve target control instance
System.Web.UI.WebControls.WebControl WebServerControl = FindControlR(this.NamingContainer, stTargetControlID);
if (WebServerControl == null) {
return;
}
// assign handler to target web control passed in
WebServerControl.Attributes.Add("onclick", "radconfirm('" + stConfirmationMessage.Replace("'", "\\'") + "', RadMsgBoxconfirmCallBackFn_" + GetUniqueValue + Key + ", " + Width + ", " + Height + ", null, '" + stTitle + "'); return false;");
// preserve the key for later use
_Key = Key;
// set postback options
_PostBackOnYes = PostBackOnYes;
_PostBackOnNo = PostBackOnNo;
_PostBackOnPrompt = false;
// create client handler script
FunctionOutputArray.Add(GenerateJavaScript());
Exit_SetConfirmation:
return;
Err_SetConfirmation:
// ERROR: Not supported in C#: ResumeStatement
}
public void SetPrompt(string stPromptMessage, string stTargetControlID, string Key, int Width = 300, int Height = 100, string stTitle = "<
strong
>Prompt</
strong
>", string stDefaultValue = "")
{
// this method exposes a passive way to bind a radprompt() window to a control
// which will be launched on the client-side
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.PromptMsg;
// set for instance processing so the class understands what method it is rendering
if (stPromptMessage == string.Empty) {
return;
}
if (stTargetControlID == string.Empty) {
return;
}
if (Key == string.Empty) {
return;
}
// retrieve target control instance
System.Web.UI.WebControls.WebControl WebServerControl = FindControlR(this.NamingContainer, stTargetControlID);
if (WebServerControl == null) {
return;
}
// assign handler to target web control passed in
WebServerControl.Attributes.Add("onclick", "radprompt('" + stPromptMessage.Replace("'", "\\'") + "', RadMsgBoxpromptCallBackFn_" + GetUniqueValue + Key + ", " + Width + ", " + Height + ", null, '" + stTitle + "', '" + stDefaultValue.Replace("'", "\\'") + "'); return false;");
// preserve the key for later use
_Key = Key;
// set postback options
_PostBackOnYes = false;
// not used here
_PostBackOnNo = false;
// not used here
_PostBackOnPrompt = true;
// create client handler script
FunctionOutputArray.Add(GenerateJavaScript());
Exit_SetPrompt:
return;
Err_SetPrompt:
// ERROR: Not supported in C#: ResumeStatement
}
//This method is used to show a simple message
public void SetAlert(string stAlertMessage, string stTargetControlID, int Width = 300, int Height = 100, string stTitle = "<
strong
>Alert</
strong
>")
{
// this method exposes a passive way to bind a radalert() window to a control
// which will be launched on the client-side
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.AlertMsg;
// set for instance processing so the class understands what method it is rendering
if (stAlertMessage == string.Empty) {
return;
}
if (stTargetControlID == string.Empty) {
return;
}
// retrieve target control instance
System.Web.UI.WebControls.WebControl WebServerControl = FindControlR(this.NamingContainer, stTargetControlID);
if (WebServerControl == null) {
return;
}
// assign handler to target web control passed in
WebServerControl.Attributes.Add("onclick", "radalert('" + stAlertMessage.Replace("'", "\\'") + "', " + Width + ", " + Height + ", '" + stTitle + "'); return false;");
// preserve the key for later use
_Key = "";
// not used here
// set postback options
_PostBackOnYes = false;
// not used here
_PostBackOnNo = false;
// not used here
_PostBackOnPrompt = false;
Exit_SetAlert:
return;
Err_SetAlert:
// ERROR: Not supported in C#: ResumeStatement
}
public void ShowAlert(string stAlertMessage, int Width = 300, int Height = 100, string stTitle = "<
strong
>Alert</
strong
>")
{
// this method exposes an active way to initiate an alert message from the server
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.AlertMsg;
// set for instance processing so the class understands what method it is rendering
if (stAlertMessage == string.Empty) {
return;
}
// assign page startup script
//Dim stScript As String = _
// "<
script
type
=
""
text/javascript""> " & vbCrLf & _
// "//
<![CDATA[" & vbCrLf & vbCrLf & _
// "Sys.Application.add_load(function() {" & vbCrLf & _
// "radalert('" & stAlertMessage.Replace("'", "\'") & "', " & Width & ", " & Height & ", '" & stTitle & "');" & _
// "})" & vbCrLf & _
// "//]]>
" & vbCrLf & _
// "</
script
>" & vbCrLf & vbCrLf
string stScript = "<
script
type=\"text/javascript\">" + Constants.vbCrLf + " //
<![CDATA[" + Constants.vbCrLf + Constants.vbCrLf + " Sys.Application.add_init(" + GetUniqueValue + "AppInit);" + Constants.vbCrLf + " function " + GetUniqueValue + "AppInit() {" + Constants.vbCrLf + " Sys.Application.add_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "RunOnce() {" + Constants.vbCrLf + " // This will only happen once per GET request to the page." + Constants.vbCrLf + " " + GetUniqueValue + "ShowAlert();" + Constants.vbCrLf + " Sys.Application.remove_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "ShowAlert() {" + Constants.vbCrLf + " radalert('" + stAlertMessage.Replace("'", "\\'") + "', " + Width + ", " + Height + ", '" + stTitle + "');" + Constants.vbCrLf + " }" + Constants.vbCrLf + "//]]>
" + Constants.vbCrLf + "</
script
>" + Constants.vbCrLf + Constants.vbCrLf;
// if using a script manager, register with the script manager, otherwise, add to ClientScript
RadScriptManager manager = RadScriptManager.GetCurrent(Page);
if (manager != null && manager.IsInAsyncPostBack) {
RadScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "_RadMsgBox_radalert", stScript, false);
} else {
if (!Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox_radalert")) {
Page.ClientScript.RegisterStartupScript(typeof(Page), "_RadMsgBox_radalert", stScript);
}
}
Exit_ShowAlert:
return;
Err_ShowAlert:
// ERROR: Not supported in C#: ResumeStatement
}
public void ShowConfirmation(string stConfirmationMessage, string Key, bool PostBackOnYes, bool PostBackOnNo, int Width = 300, int Height = 100, string stTitle = "<
strong
>Confirm</
strong
>")
{
// this method exposes an active way to initiate a confirmation message from the server
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.ConfirmMsg;
// set for instance processing so the class understands what method it is rendering
if (stConfirmationMessage == string.Empty) {
return;
}
if (Key == string.Empty) {
return;
}
// assign page startup script
// Dim stScript As String = _
// "<
script
type
=
""
text/javascript""> " & vbCrLf & _
// "//
<![CDATA[" & vbCrLf & vbCrLf & _
// "Sys.Application.add_load(function() {" & vbCrLf & _
// "radconfirm('" & stConfirmationMessage.Replace("'", "\'") & "', RadMsgBoxconfirmCallBackFn_" & Key & ", " & Width & ", " & Height & ", null, '" & stTitle & "');" & _
// "})" & vbCrLf & _
// "//]]>
" & vbCrLf & _
// "</
script
>" & vbCrLf & vbCrLf
// If Not Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox_radconfirm") Then
// Page.ClientScript.RegisterStartupScript(GetType(Page), "_RadMsgBox_radconfirm", stScript)
// End If
string stScript = "<
script
type=\"text/javascript\">" + Constants.vbCrLf + " //
<![CDATA[" + Constants.vbCrLf + Constants.vbCrLf + " Sys.Application.add_init(" + GetUniqueValue + "AppInit);" + Constants.vbCrLf + " function " + GetUniqueValue + "AppInit() {" + Constants.vbCrLf + " Sys.Application.add_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "RunOnce() {" + Constants.vbCrLf + " // This will only happen once per GET request to the page." + Constants.vbCrLf + " " + GetUniqueValue + "ShowConfirmation();" + Constants.vbCrLf + " Sys.Application.remove_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "ShowConfirmation() {" + Constants.vbCrLf + " radconfirm('" + stConfirmationMessage.Replace("'", "\\'") + "', RadMsgBoxconfirmCallBackFn_" + GetUniqueValue + Key + ", " + Width + ", " + Height + ", null, '" + stTitle + "');" + " }" + Constants.vbCrLf + "//]]>
" + Constants.vbCrLf + "</
script
>" + Constants.vbCrLf + Constants.vbCrLf;
// if using a script manager, register with the script manager, otherwise, add to ClientScript
RadScriptManager manager = RadScriptManager.GetCurrent(Page);
if (manager != null && manager.IsInAsyncPostBack) {
RadScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "_RadMsgBox_radconfirm", stScript, false);
} else {
if (!Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox_radconfirm")) {
Page.ClientScript.RegisterStartupScript(typeof(Page), "_RadMsgBox_radconfirm", stScript);
}
}
// preserve the key for later use
_Key = Key;
// set postback options
_PostBackOnYes = PostBackOnYes;
_PostBackOnNo = PostBackOnNo;
_PostBackOnPrompt = false;
// create client handler script
FunctionOutputArray.Add(GenerateJavaScript());
Exit_ShowConfirmation:
return;
Err_ShowConfirmation:
// ERROR: Not supported in C#: ResumeStatement
}
public void ShowPrompt(string stPromptMessage, string Key, int Width = 300, int Height = 100, string stTitle = "<
strong
>Prompt</
strong
>", string stDefaultValue = "")
{
// this method exposes an active way to initiate an prompt message from the server
// ERROR: Not supported in C#: OnErrorStatement
_MsgType = MsgType.PromptMsg;
// set for instance processing so the class understands what method it is rendering
if (stPromptMessage == string.Empty) {
return;
}
if (Key == string.Empty) {
return;
}
// assign page startup script
// Dim stScript As String = _
// "<
script
type
=
""
text/javascript""> " & vbCrLf & _
// "//
<![CDATA[" & vbCrLf & vbCrLf & _
// "Sys.Application.add_load(function() {" & vbCrLf & _
// "radprompt('" & stPromptMessage.Replace("'", "\'") & "', RadMsgBoxpromptCallBackFn_" & Key & ", " & Width & ", " & Height & ", null, '" & stTitle & "', '" & stDefaultValue.Replace("'", "\'") & "');" & _
// "})" & vbCrLf & _
// "//]]>
" & vbCrLf & _
// "</
script
>" & vbCrLf & vbCrLf
//
// If Not Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox_radprompt") Then
// Page.ClientScript.RegisterStartupScript(GetType(Page), "_RadMsgBox_radprompt", stScript)
// End If
string stScript = "<
script
type=\"text/javascript\">" + Constants.vbCrLf + " //
<![CDATA[" + Constants.vbCrLf + Constants.vbCrLf + " Sys.Application.add_init(" + GetUniqueValue + "AppInit);" + Constants.vbCrLf + " function " + GetUniqueValue + "AppInit() {" + Constants.vbCrLf + " Sys.Application.add_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "RunOnce() {" + Constants.vbCrLf + " // This will only happen once per GET request to the page." + Constants.vbCrLf + " " + GetUniqueValue + "ShowPrompt();" + Constants.vbCrLf + " Sys.Application.remove_load(" + GetUniqueValue + "RunOnce);" + Constants.vbCrLf + " }" + Constants.vbCrLf + " function " + GetUniqueValue + "ShowPrompt() {" + Constants.vbCrLf + " radprompt('" + stPromptMessage.Replace("'", "\\'") + "', RadMsgBoxpromptCallBackFn_" + GetUniqueValue + Key + ", " + Width + ", " + Height + ", null, '" + stTitle + "', '" + stDefaultValue.Replace("'", "\\'") + "');" + " }" + Constants.vbCrLf + "//]]>
" + Constants.vbCrLf + "</
script
>" + Constants.vbCrLf + Constants.vbCrLf;
// if using a script manager, register with the script manager, otherwise, add to ClientScript
RadScriptManager manager = RadScriptManager.GetCurrent(Page);
if (manager != null && manager.IsInAsyncPostBack) {
RadScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "_RadMsgBox_radprompt", stScript, false);
} else {
if (!Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox_radprompt")) {
Page.ClientScript.RegisterStartupScript(typeof(Page), "_RadMsgBox_radprompt", stScript);
}
}
// preserve the key for later use
_Key = Key;
// set postback options
_PostBackOnYes = false;
// not used here
_PostBackOnNo = false;
// not used here
_PostBackOnPrompt = true;
// create client handler script
FunctionOutputArray.Add(GenerateJavaScript());
Exit_ShowPrompt:
return;
Err_ShowPrompt:
// ERROR: Not supported in C#: ResumeStatement
}
#endregion
#region "Private Properties"
private string GetUniqueValue {
// Return Me.UniqueID.Replace("$", "_")
get { return this.ID; }
}
#endregion
//We prepare the control to send the function javascript
protected override void OnPreRender(EventArgs e)
{
// ERROR: Not supported in C#: OnErrorStatement
//register all the relevant scripts in the control
string stScriptFinal = "";
foreach (string stScript in FunctionOutputArray) {
stScriptFinal += stScript;
}
if (!string.IsNullOrEmpty(stScriptFinal)) {
// if using a script manager, register with the script manager, otherwise, add to ClientScript
// If manager IsNot Nothing AndAlso manager.IsInAsyncPostBack Then
RadScriptManager manager = RadScriptManager.GetCurrent(Page);
if (manager != null && manager.IsInAsyncPostBack) {
RadScriptManager.RegisterStartupScript(Page, typeof(Page), "_RadMsgBox", stScriptFinal, false);
} else {
if (!Page.ClientScript.IsStartupScriptRegistered("_RadMsgBox")) {
Page.ClientScript.RegisterStartupScript(typeof(Page), "_RadMsgBox", stScriptFinal);
}
}
// make sure to clear the output array so other modules who depend on this list don't get confused
FunctionOutputArray.Clear();
}
base.OnPreRender(e);
Exit_OnPreRender:
return;
Err_OnPreRender:
// ERROR: Not supported in C#: ResumeStatement
}
private string GenerateJavaScript()
{
string functionReturnValue = null;
// ERROR: Not supported in C#: OnErrorStatement
// declare post-back references
string miPostBackOnYes = "";
string miPostBackOnNo = "";
string miPostBackOnPrompt = "";
// depending on the options set from the invoking method, we
// generate postback references with the _Key appended
// to pre-set identification values. This allows us to have multiple
// controls on a page raise events and utilize this control with
// a single instansiation
if (_PostBackOnYes) {
miPostBackOnYes = Page.ClientScript.GetPostBackEventReference(this, "Yes" + _Key);
}
if (_PostBackOnNo) {
miPostBackOnNo = Page.ClientScript.GetPostBackEventReference(this, "No_" + _Key);
}
if (_PostBackOnPrompt) {
miPostBackOnPrompt = Page.ClientScript.GetPostBackEventReference(this, "PRM" + _Key);
}
//
// following function no longer used, but can be utilized to
// cleanly added load handler function smoothly on top of any
// other page load handlers in the event that the control
// needs to do this...
// note: this function probably doesn't work with AJAX
//
// function addLoadEvent(func) {
// var oldonload = window.onload;
// if (typeof window.onload != 'function') {
// window.onload = func;
// } else {
// window.onload = function() {
// if (oldonload) {
// oldonload();
// }
// func();
// }
// }
// }
string stScript = "";
switch (_MsgType) {
case MsgType.ConfirmMsg:
stScript = "<
script
type=\"text/javascript\"> " + Constants.vbCrLf + "//
<![CDATA[" + Constants.vbCrLf + Constants.vbCrLf + "function RadMsgBoxconfirmCallBackFn_" + GetUniqueValue + _Key + "(arg) {" + Constants.vbCrLf + Constants.vbCrLf + " if (arg) {" + Constants.vbCrLf + miPostBackOnYes + Constants.vbCrLf + " } else { " + Constants.vbCrLf + miPostBackOnNo + Constants.vbCrLf + " }" + Constants.vbCrLf + "}" + Constants.vbCrLf + Constants.vbCrLf + "//]]>
" + Constants.vbCrLf + "</
script
>" + Constants.vbCrLf + Constants.vbCrLf;
break;
case MsgType.PromptMsg:
string stCustomPostBackOnPrompt = miPostBackOnPrompt.Replace("'PRM" + _Key + "'", "'" + _Key + "' + '|' + arg");
stScript = "<
script
type=\"text/javascript\"> " + Constants.vbCrLf + "//
<![CDATA[" + Constants.vbCrLf + Constants.vbCrLf + "function RadMsgBoxpromptCallBackFn_" + GetUniqueValue + _Key + "(arg) {" + Constants.vbCrLf + Constants.vbCrLf + stCustomPostBackOnPrompt + Constants.vbCrLf + "}" + Constants.vbCrLf + Constants.vbCrLf + "//]]>
" + Constants.vbCrLf + "</
script
>" + Constants.vbCrLf + Constants.vbCrLf;
break;
}
functionReturnValue = stScript;
Exit_GenerateJavaScript:
return functionReturnValue;
Err_GenerateJavaScript:
functionReturnValue = "";
// ERROR: Not supported in C#: ResumeStatement
return functionReturnValue;
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
//We draw the control
if (IsInDesignMode(this)) {
// If we are in design-mode, simply show the ID of the control
writer.Write(this.ID);
}
// Dim miSB As System.Text.StringBuilder = New System.Text.StringBuilder(_Message)
// miSB.Replace(Microsoft.VisualBasic.vbCr, " "c)
// miSB.Replace(Microsoft.VisualBasic.vbLf, " "c)
// miSB.Replace("""", "'"c)
base.Render(writer);
}
//Private function to verify if the control is in design mode
private static bool IsInDesignMode(System.Web.UI.WebControls.WebControl QueControl)
{
bool DesignMode = false;
try {
DesignMode = QueControl.Site.DesignMode;
} catch {
}
return DesignMode;
}
//this method is executed based on user action (clicks) from post backs
protected void RaisePostBackEvent(string eventArgument)
{
// ERROR: Not supported in C#: OnErrorStatement
switch (eventArgument.Substring(0, 3)) {
case "Yes":
// if the first part of the event argument is "Yes", then the rest is the key
// which is raised to the client here
if (YesSelected != null) {
YesSelected(this, eventArgument.Substring(3));
}
break;
case "No_":
// if the first part of the event argument is "No_", then the rest is the key
// which is raised to the client here
if (NoSelected != null) {
NoSelected(this, eventArgument.Substring(3));
}
break;
default:
// should be a prompt response
int delim = eventArgument.IndexOf("|");
// parse out concatenated key/value pair
string key = eventArgument.Substring(0, delim);
string value = eventArgument.Substring(delim + 1, eventArgument.Length - (delim + 1));
if (PromptResponse != null) {
PromptResponse(this, key, value);
}
break;
}
Exit_RaisePostBackEvent:
return;
Err_RaisePostBackEvent:
// ERROR: Not supported in C#: ResumeStatement
}
// recursive function to walk the control tree of a Page (or container control as called)
// and search for the *first* occurrence of the "id" of the control being sought
private Control FindControlR(Control root, string id)
{
Control controlFound = null;
if ((root != null)) {
controlFound = root.FindControl(id);
if ((controlFound != null)) {
return controlFound;
}
foreach (Control c in root.Controls) {
controlFound = FindControlR(c, id);
if ((controlFound != null)) {
return controlFound;
}
}
}
return null;
}
}