As you may already know, there are a few JavaScript methods available to the SIX Web developers. Most, if not all of them, are placed in the Scripts folder, and there are methods for almost every need. In this post I’m going to look at the messagebox functions and round it all off making my own messagebox version.
In the Scripts/Dialog.js file you have several messagebox functions available. Three of the most common are:
YesNo (title, text, dialogType, checkBoxText, callBack, context) YesNoCancel (title, text, dialogType, callBack, context) ThreeButton (title, text, buttonText1, buttonText2, dialogType, context, callBack)
These methods are what you can call self explaining, but if you need to read more about them, open the Web GUI Api help file (SO.WebGUI.chm). Anyway, here is an example:
Dialog.YesNo('My Yes/No Message Box', 'Are you sure you want to do the stuff you are doing now?', 'question', '', 'MyCallBack', '');
function MyCallBack(res)
{
alert(res);
}
Running this will display this messagebox:

The problem occurs when you want to show a messagebox with two customizable buttons only… and off curse that was what I needed.
I you use the Reflector tool to dig into the SIX Web code, you will find out that the javascripts function above actually are Ajax call to methods on the server. So, using this as a base, I created my own messagebox method using the SoDialogBase class:
Imports SuperOffice.CRM.Web.UI.Controls
Imports SuperOffice.Globalization
Imports System.Web.UI
Namespace Omere.GUI
Public Class TwoButtonDialog
Inherits SoDialogBase
Private _Button1 As String = ""
Private _Button2 As String = ""
Private _Text As String = ""
Private _Title As String = ""
Public Sub New(ByVal title As String, ByVal [text] As String, ByVal buttonText1 As String, ByVal buttonText2 As String)
_Text = [text]
_Title = title
_Button1 = buttonText1
_Button2 = buttonText2
MyBase.ID = ("twobuttondialog" & DateTime.Now.Ticks.ToString)
End Sub
Public Sub AddDialogButtons()
Dim callBackFunction As String = MyBase.CallBackFunction
callBackFunction = (("Dialog.inlineDialogCallback(this, '" & MyBase.CallBackFunction & "',") & "{0}, checkBoxValues, radioValues);")
MyBase.AddButtons(New ButtonDefinition() {New ButtonDefinition(_Button1, String.Format(callBackFunction, 1), True), New ButtonDefinition(_Button2, String.Format(callBackFunction, 2), True)})
End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
If _Text.StartsWith("[") Then
_Text = ResourceManager.GetString(_Text)
End If
If _Title.StartsWith("[") Then
MyBase.Title = ResourceManager.GetString(_Title).ToUpperInvariant
Else
MyBase.Title = _Title
End If
MyBase.AddText(_Text)
Me.AddDialogButtons()
MyBase.Render(writer)
End Sub
End Class
End Namespace
Since this method you be available on the client side, I need to pack it into to an "Ajax" method. So, I'm creating a new class:
Imports SuperOffice.CRM.Web.UI
Imports SuperOffice.CRM.Web.UI.Controls.SoDialogBase
Namespace Omere.GUI
Public Class AjaxMethods
Public Function TwoButtonDialog(ByVal title As String, ByVal [text] As String, ByVal buttonText1 As String, ByVal buttonText2 As String, ByVal dialogType As String, ByVal context As String, ByVal callBack As String) As String
dialogType = dialogType.ToLowerInvariant
Dim none As DialogTypeEnum = DialogTypeEnum.None
Dim str3 As String = dialogType
If (str3 IsNot Nothing) Then
If Not (str3 = "warning") Then
If (str3 = "error") Then
none = DialogTypeEnum.Error
ElseIf (str3 = "question") Then
none = DialogTypeEnum.Question
End If
Else
none = DialogTypeEnum.Warning
End If
End If
Dim control As New TwoButtonDialog(title, [text], buttonText1, buttonText2)
control.DialogType = none
control.CallBackFunction = callBack
Try
Return RenderHelper.RenderControlToString(control).Replace(ChrW(10), "")
Catch exception As Exception
Return ""
End Try
End Function
End Class
End Namespace
As always when you are working with Ajax methods, we need to add a line in the SoObjectMapping.config:
<object type="AjaxMethod" mappingname="AjaxMethodsGUI" assemblyname="Omere.GUI" objectname="Omere.GUI.AjaxMethods" xusing_ajaxnet="true"/>
At the client side I added this script:
function OmereTwoButton(title, text, buttonText1, buttonText2, dialogType, context, callBack)
{
var src = AjaxMethodDispatcher.CallSync("Omere.GUI.AjaxMethodsGUI.TwoButtonDialog", "", title, text, buttonText1, buttonText2, dialogType, context, callBack);
Dialog.displayInlineModalDialog(src, context);
}
Calling the OmereTwoButton method with this code
OmereTwoButton("My Own Messagebox", "Yes! This is my own MessageBox","Button1","Button2",'info', '', 'MyCallBack');
result in:

There is only one catch! The button text is handled as resource tags, so you have to use a resource file to specify the text.