Server Side MsgBox User Control for radconfirm, radalert and radprompt

Thread is closed for posting
62 posts, 0 answers
  1. 7AD05C47-11C0-4947-8827-A70E9EB9B154
    7AD05C47-11C0-4947-8827-A70E9EB9B154 avatar
    28 posts
    Member since:
    Dec 2009

    Posted 06 Apr 2010 Link to this post

    Hi Alberto

    Yes, I implemented RadMsg using Q3 2009 Telerik.Web.UI
    Works like a champ.  Used it for radconfirm control.  Glad to answer any specific question you might have.
  2. 6A0B693C-ED2F-4EB8-96AA-F891E6F65B29
    6A0B693C-ED2F-4EB8-96AA-F891E6F65B29 avatar
    34 posts
    Member since:
    Sep 2012

    Posted 21 Jul 2010 Link to this post

    Hi David, hi guys,
    I've in my page a RadWindowManager, RadMsgBox and a RadSplitter with 2 RadPane.
    RadSplitter is in a RadAjaxPanel.
    In one RadPane I have a button width this server-side code:

    RadMsgBox1.ShowConfirmation("Test", "s", True, False, 400, 200, "Test Window")

    When click on the button, server-side event CLICK fires but the Confirmation Window don't appears.
    If I move the button outside the RadAjaxPanel the Window appears correctly.

    Can you help me?

    Cheers

    Fabrizio
  3. 16E59879-3A86-4D60-B18A-A8BDA7EB935E
    16E59879-3A86-4D60-B18A-A8BDA7EB935E avatar
    539 posts
    Member since:
    Apr 2004

    Posted 30 Jul 2010 Link to this post

    HI..
    Can anyone please post the current code in C#? 
    Thanks again... this will be a big help.
  4. 6574B2CD-66ED-4438-A1F9-2F5BAA993FE5
    6574B2CD-66ED-4438-A1F9-2F5BAA993FE5 avatar
    3 posts
    Member since:
    May 2010

    Posted 16 Aug 2010 Link to this post

    I tried to use the code converter to convert the VB class to C# but it resulted in multiple errors that after several hours of trying I am unable to troubleshoot. 
    If anyone comes up with a C# version of the class please post it. 
    Thanks
  5. 16E59879-3A86-4D60-B18A-A8BDA7EB935E
    16E59879-3A86-4D60-B18A-A8BDA7EB935E avatar
    539 posts
    Member since:
    Apr 2004

    Posted 02 Sep 2010 Link to this post

    Ditto - with the code converter
  6. 7D38EAE4-8D2E-4526-9256-42BE370946A7
    7D38EAE4-8D2E-4526-9256-42BE370946A7 avatar
    3 posts
    Member since:
    Jun 2004

    Posted 14 Sep 2010 Link to this post

    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;
        }
      
      
    }
  7. F3E58BC9-F8AC-4073-A373-D4DC69043C98
    F3E58BC9-F8AC-4073-A373-D4DC69043C98 avatar
    72 posts
    Member since:
    Sep 2008

    Posted 27 Sep 2010 Link to this post

    Hi David,

    First thanks for this controls. We use it a lot in our application. Very usefull.
    I Just update my application with the laste version of telerik (RadControls for ASP.NET Q2 2010) but MsgBox don't work anymore.
    Works MsgBox with Telerik Q2 2010 DLL? Or do I need to change something?

    In advance thanks for your answer.

    Edwin.
  8. 4348CCED-8772-4663-A34B-8F4E4138C317
    4348CCED-8772-4663-A34B-8F4E4138C317 avatar
    16 posts
    Member since:
    Jun 2007

    Posted 27 Sep 2010 Link to this post

    Edwin, it should work with the latest release. Most likely, you need to recompile the source code with the latest library to ensure that you references are updated. Good luck.
  9. F3E58BC9-F8AC-4073-A373-D4DC69043C98
    F3E58BC9-F8AC-4073-A373-D4DC69043C98 avatar
    72 posts
    Member since:
    Sep 2008

    Posted 27 Sep 2010 Link to this post

    Hi David,

    Thank you for your quick answer.
    I recompile the project and now everything works fine.

    Regards,
    Edwin.
  10. 63286A27-8186-4C38-9D0D-57EF710174E0
    63286A27-8186-4C38-9D0D-57EF710174E0 avatar
    4 posts
    Member since:
    Feb 2009

    Posted 15 Oct 2010 Link to this post

    Very, Very intersting topic.  Can someone post a complete solution of the source and a test webpage using this code?  Following the chain, I am not sure where I should begin.  Either C# or VB.NET is fine by me.  Can convert either way, including the issue of VB.NET using overloaded functions/subs and on error statements and C# doesn't!

    Thanks,
    /dz
  11. F3E58BC9-F8AC-4073-A373-D4DC69043C98
    F3E58BC9-F8AC-4073-A373-D4DC69043C98 avatar
    72 posts
    Member since:
    Sep 2008

    Posted 21 Oct 2010 Link to this post

    Hi David,

    Like I already say we work now with .net4 C# (vs2010) and telerik Q2 2010.
    We recompile the radmsgbox code but we still have problem if the radmsgbox is not in a masterpage.
    We try different way to solve the problem but nothing work.

    Deed you already try the msgBox with .net4 C# and telerik Q2 2010?

    In advance thanks for your help.

    Regards,

    Edwin.

  12. EC333E6A-D098-481C-AB1E-C04AC44C8080
    EC333E6A-D098-481C-AB1E-C04AC44C8080 avatar
    13 posts
    Member since:
    Jul 2010

    Posted 23 Oct 2010 Link to this post

    First off, David, thanks for the contribution.  This is exactly what I was looking for...  I'm hoping that Telerik integrates this as part of the radcontrols framework.

    Edwin,  I had a similar problem with asp.net/c#/latest version of radcontrols/masterpages.  Using the RadMsgbox without master pages, it worked fine, but with masterpages the events were never caught in my handlers.  In doing some digging around in the asp.net event firing mechanisms,  I found a solution.  

    Without using masterpages, to wire up the events, I was using the snipplet below.  
    protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              RadMsgBox1.YesSelected += new RadMsgBox.RadMsgBox.YesSelectedEventHandler(RadMsgBox1_YesSelected); 
              
          }
      }



    This worked fine until I migrated my POC code back into my real project (which uses master pages) & the event stopped working.  So I migrated the event wireup to the below & it worked as planned.

    protected override void OnInit(EventArgs e)
    {
        this.InitializeComponent();
        base.OnInit(e);
    }
     
    private void InitializeComponent()
    {
          RadMsgBox1.YesSelected += new RadMsgBox.RadMsgBox.YesSelectedEventHandler(RadMsgBox1_YesSelected);   
    }


    Hope this helps,  Joe.
  13. 4348CCED-8772-4663-A34B-8F4E4138C317
    4348CCED-8772-4663-A34B-8F4E4138C317 avatar
    16 posts
    Member since:
    Jun 2007

    Posted 23 Oct 2010 Link to this post

    Hi all, great questions. I am not making enhancements to the server control, so the code is "as is" ;-) but it seems several folks have been able to port the code successfully to C#. Using VB, I have never had wire-up problems regardless of master page usage or not. But it looks like the solution outlined in this last post by Joe is a good one.

    One thing to remember with this server control is that because it references the Telerik library itself, it must be recomplied when a new RadControls release is installed in development/production. Not updating this control by recompiling is the most common problem folks seem to have.

    Good luck.
  14. F3E58BC9-F8AC-4073-A373-D4DC69043C98
    F3E58BC9-F8AC-4073-A373-D4DC69043C98 avatar
    72 posts
    Member since:
    Sep 2008

    Posted 25 Oct 2010 Link to this post

    Hi David, Joe,

    Thank you for your answers.
    It would be effectively great if Telerik include this control inside the radcontrols framework ;-)

    I will try your suggestions.

    Thanks again.

    Regards,

    Edwin.
  15. B623D68F-4685-4559-A4DE-D2B4DE384F3E
    B623D68F-4685-4559-A4DE-D2B4DE384F3E avatar
    49 posts
    Member since:
    Sep 2012

    Posted 04 Nov 2010 Link to this post

    Hi David
    Just a quick thank you from me for posting this article and code.
    Definately saved me a lot of time.
    I agree with other comments that Telerik ought to 'productise' this type of functionality as it is essential to architecting LOB server based applications to be able to prompt the user from server-side business logic.

    Regards, Garry.
  16. 44201456-27DC-4827-A423-AEB8B4FD1B84
    44201456-27DC-4827-A423-AEB8B4FD1B84 avatar
    12 posts
    Member since:
    Apr 2009

    Posted 20 Dec 2010 Link to this post

    Hi everyone,
    I´m new in Telerik Web Controls, I try to implement this library in my solution and the window not appears.
    Anybody could put a simple complete example that works to see how I´m doing wrong.
    Thanks.
     
  17. 4348CCED-8772-4663-A34B-8F4E4138C317
    4348CCED-8772-4663-A34B-8F4E4138C317 avatar
    16 posts
    Member since:
    Jun 2007

    Posted 20 Dec 2010 Link to this post

    It's easy. First comiple the code into the RadMsgBox.DLL. Add it as a reference to your project.

    In your .ASPX page:

    <%

     

    @ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="RadMsgBox" Namespace="RadMsgBox" Assembly="RadMsgBox" %>

     

    <html>
    <body>

     

     

    <!-- you need a script manager - I use the ASP one, but you can use Telerik's -->
    <
    asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <!-- the window manager is also needed for the radprompt(), radalert() and radconfirm() dialogs -->
    <telerik:RadWindowManager id="RadWindowManager1" runat="server" skin="Web20" ReloadOnShow="false" DestroyOnClose="false" VisibleOnPageLoad="false" ShowContentDuringLoad="false">

     

    <!-- Instansiate the RadMsgBox control -->
    <RadMsgBox:RadMsgBox ID="RadMsgBox1" runat="server" />

    </body>
    </html>

    In your code-behind (here a .VB example):

    Sub Page_Load

     

     

        If Not IsPostBack Then
            
    ' first time in

     

     

     

        End If

     

        ' set RadMsgBox here if you want to assign to a button directly without code-behind actions
        in this case, we simply assign the RadMsgBox SetConfirmation method to a Submit Button
        
    Me.RadMsgBox1.SetConfirmation("Submit this Order?", Me.btnSubmitOrder.ID, "SUBMIT", True, False)

    End Sub

    Protected Sub SomeOtherButton_Click () Handled SomeOtherButton.Click
        
        '  As an alternative, you can call the instant methods of the RadMsgBox directly from
        ' the code-behind action event of a button or some other form element as needed
            
            Me.RadMsgBox1.ShowAlert("Throw up an alert box")

    End Sub

     

     

    Private Sub RadMsgBox1_YesSelected(ByVal sender As Object, ByVal Key As String) Handles RadMsgBox1.YesSelected
    '  And if you do use one of the "Confirm" methods, don't forget the all important YesSelected or NoSelected
    '  events to properly handle the response from the RadMsgBox

        Select
    Case Key

     

     

     

            Case "SUBMIT"

     

     

     

            Case "DELETE"

     

     

     

        End Select

     

     

     

    End Sub

     




  18. 44201456-27DC-4827-A423-AEB8B4FD1B84
    44201456-27DC-4827-A423-AEB8B4FD1B84 avatar
    12 posts
    Member since:
    Apr 2009

    Posted 20 Dec 2010 Link to this post

    In spain we said, "1000 thanks".
    That´s what i need, I didn´t understand what key is, now everything is clear.
    I think a lot of people can use your example and your great solution.
    Thanks a lot.
    Best Regards, David.
  19. 7960B23C-11E1-4EBC-AF96-3A5B7CA3D98B
    7960B23C-11E1-4EBC-AF96-3A5B7CA3D98B avatar
    18 posts
    Member since:
    Sep 2010

    Posted 11 Jan 2011 Link to this post

    Hello,
    I have a question, and will be glad if someone can answer me:
    in my solution i use one page, that when clicking on its button i first check clients things and then show confirm - and after answering "yes" i want to go to the seerver. Actually for going to server i use button click function but then, if i put ajax between the button and othe control - so going to server doesnt work, and if i remove the ajax so it akes full postback and then some parameters i have on client are getting the default value and it must not be.
    i wanted to use the solution above u are talking about, but actually how can i call from client to the "showconfrimation" of the msgbox?
    or if u have other solution for my problem?

    thanks,
    gz
  20. 7960B23C-11E1-4EBC-AF96-3A5B7CA3D98B
    7960B23C-11E1-4EBC-AF96-3A5B7CA3D98B avatar
    18 posts
    Member since:
    Sep 2010

    Posted 13 Jan 2011 Link to this post

    Hello,
    i have found solution by calling AjaxRequest in my page wich delegates in code behind the ajaxrequest of the masterpage,  and using  the confirmation of the msgBox u explained above, but now i have another big bug:
    on first time i call the AjaxRequest it works, and the confirmation is shown without full postback, but the second time i call it on another click - it falss with this error:
    Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.
    Anybody knows why?

    thanks,
    gz
  21. 4348CCED-8772-4663-A34B-8F4E4138C317
    4348CCED-8772-4663-A34B-8F4E4138C317 avatar
    16 posts
    Member since:
    Jun 2007

    Posted 13 Jan 2011 Link to this post

    Unfortunately, I think its impossible to troubleshoot your specific issue, but are you using the right version of the control? There is an AJAX version and a NON Ajax version under this thread. Make sure you have downloaded and compiled the AJAX version. Good luck
  22. 29820072-1A59-429B-9F6F-C2DE850057BB
    29820072-1A59-429B-9F6F-C2DE850057BB avatar
    11 posts
    Member since:
    Jul 2008

    Posted 15 Jan 2011 Link to this post

    Hello,

    I must be doing something wrong, I'm using the assembly (RadMsgBox.dll) but I can't make it work with AJAX.
    If I remove the OnClick button from the UpdatePanel it works fine.

    David, could you please attach or send me the latest RadMsgBox.dll ?

    Thanks!


  23. B623D68F-4685-4559-A4DE-D2B4DE384F3E
    B623D68F-4685-4559-A4DE-D2B4DE384F3E avatar
    49 posts
    Member since:
    Sep 2012

    Posted 26 Jul 2011 Link to this post

    I have now upgraded to IE9 and my code is now broke.
    I am now getting JScript runtime errors: http://www.trisys.co.uk/images/telerik/ie9_radprompt.jpg
    Probably proves my point that Telerik ought to have properly componentised this functionality because volunteers' code will eventually break on new browsers, as has been proven in this case.
  24. A1CE16C4-4C2E-464E-BF18-532525D276CA
    A1CE16C4-4C2E-464E-BF18-532525D276CA avatar
    5948 posts
    Member since:
    Apr 2022

    Posted 26 Jul 2011 Link to this post

    Hi guys,

    This code library is not created by Telerik and thus supporting it and any issues that may arise from it are not Telerik's responsibility.

      As for the issue you experience under IE9 - it seems that you are using an older version of our controls that has been released prior to the advent of IE9. This seems like one of the known issues under IE9 which has been fixed in Q1 2011 (which is the first version to support IE9, as it was released in a matter of days with IE9). The issue stems from a breaking change in the way iframes are created under IE9 and not from a bug in our controls.


    Greetings,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  25. B623D68F-4685-4559-A4DE-D2B4DE384F3E
    B623D68F-4685-4559-A4DE-D2B4DE384F3E avatar
    49 posts
    Member since:
    Sep 2012

    Posted 26 Jul 2011 Link to this post

    Marin
    Thanks for your reply - yes you are right that the last time I compiled and tested this code was using a previous version.
    This also explains why the site is failing on IE9, but only for RadPrompt.
    I have upgraded to the latest version, but had hoped that Telerik would have provided an easy to use method of allowing ASP.Net server-side code to draw JQuery style popup windows. Is this the case in the latest software?

    Regards, Garry.

  26. A1CE16C4-4C2E-464E-BF18-532525D276CA
    A1CE16C4-4C2E-464E-BF18-532525D276CA avatar
    5948 posts
    Member since:
    Apr 2022

    Posted 27 Jul 2011 Link to this post

    Hi Garry,

    Since Q1 2011 the RadWindowManager provides server-side methods to call the three predefined dialogs (RadAlert, RadConfirm and RadPrompt). More information on the matter is available in this online demo and in the documentation.


    Kind regards,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  27. B623D68F-4685-4559-A4DE-D2B4DE384F3E
    B623D68F-4685-4559-A4DE-D2B4DE384F3E avatar
    49 posts
    Member since:
    Sep 2012

    Posted 28 Jul 2011 Link to this post

    OK Marin, thanks for that pointer.
    This technique though is far too Javascript oriented and therefore unmaintainable.
    I can see how to invoke the RadAlert from the server - great.
    However the response is captured by Javascript on the client. This is NOT what an ASP.Net server application requires.
    We require a response to the server application as a rediection to another page depending upon which button is clicked.
    The server side ASP.Net application will only know at run-time, which pages to redirect to.
    Your solution requires that the developer build javascript redirects for each and every page in the ASP.Net project.

    For example in server side ASP.Net code:    
        Call RadAlert(OkButton:=AddressOf MyOKFunction, CancelButton:=AddressOf MyCancelFunction, MessageText:=".......")
    ...
    Private Sub MyOKFunction
        ' Do something after the user confirmed OK
    End Sub
    Private Sub MyCancelFunction
         ' Do something after the user cancelled
    End Sub
  28. A1CE16C4-4C2E-464E-BF18-532525D276CA
    A1CE16C4-4C2E-464E-BF18-532525D276CA avatar
    5948 posts
    Member since:
    Apr 2022

    Posted 29 Jul 2011 Link to this post

    Hello Garry,

    Please note that the RadWindow (and therefore RadAlert, RadConfirm and RadPrompt as well) is a client-side object, designed to deliver rich client-side experience, therefore most of its use comes in JavaScript.

    What I can advise if you want to have server-side events attached to the confirmation buttons is that you use a separate RadWindow (modal, of course, with some small size to resemble a confirm box) and have the desired buttons with the needed server-side handlers in its content template. This window can be declared on the page and opened by injecting a JavaScript function from the server, or can be created dynamically in the code behind once and not recreated after a postback.

    For your convenience I created and attached a simple example of this approach.


    All the best,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  29. 6D907067-890E-43D3-BC85-F17253ECA7CF
    6D907067-890E-43D3-BC85-F17253ECA7CF avatar
    9 posts
    Member since:
    Aug 2008

    Posted 09 Feb 2012 Link to this post

    Exc Class, Thanks !!
  30. F0EDDE15-A8B6-407A-A81A-564DF9E8130E
    F0EDDE15-A8B6-407A-A81A-564DF9E8130E avatar
    9 posts
    Member since:
    Mar 2011

    Posted 28 Feb 2012 Link to this post

    I just wanted to thank David Eisner for this wonderful bit of code. 
    Also, why has Telerik not included this or atleast its functionality into the actual controls??  I cant believe that this functionality would go un-used as part of the control suite.


Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.