View Full Version : Custom Prompt MessageBox

Nov 04, 2009, 6:39 AM
In the examples the prompt style message box calls a javascript function using

Ext.Msg.Prompt("Name", "Please enter your name:", new JFunction { Fn = "showResultText" }).Show();

I want to call an AjaxMethod where I will do some database updates. How do I get the text from the prompt. I was planning to use this syntax:-

Ext.Msg.Prompt("Name", "Please enter the new username:", new MessageBox.ButtonsConfig
Ok = new MessageBox.ButtonConfig { Handler = "Coolite.AjaxMethods.ChangeUsernameCallback('" + theText + '")", Text = "OK" },
Cancel = new MessageBox.ButtonConfig { Text = "Cancel" }

Where 'theText' would hold the value of the text from the prompt input.

Nov 04, 2009, 10:47 AM
<script runat="server">
<AjaxMethod(Type:=AjaxEventType.Load, ViewStateMode:=ViewStateMode.Exclude)> _
Public Sub ChangeUsernameCallback(ByVal newname As String)
'do some db updates

'optionally alert
Ext.MessageBox.Alert("Success", String.Format("Username changed successfully to '{0}'!", newname)).Show()
End Sub

Public Sub ServerSidePromptCallback(ByVal sender As Object, ByVal e As AjaxEventArgs)
Ext.Msg.Prompt("Title", "Please enter new username:", New JFunction() With {.Fn = "function(btn, text) {if (btn == 'ok') {Coolite.AjaxMethods.ChangeUsernameCallback(text); }}"}).Show()
End Sub


<script type="text/javascript">
function promptUsername() {
Ext.Msg.prompt('Title', 'Please enter new username:', function(btn, text) {
if (btn == 'ok') {

<asp:Panel runat="server" ID="pnlTools" Height="50px">
<ext:Toolbar runat="server" ID="wsTools">
<ext:Button runat="server" Text="Client Prompt (faster)">
<Click Handler="Ext.Msg.prompt('Title', 'Please enter new username:', function(btn, text) {if (btn == 'ok') {Coolite.AjaxMethods.ChangeUsernameCallback(text); }})" />
<ext:Button runat="server" Text="Client Prompt (faster and cleaner)">
<Click Fn="promptUsername" />
<ext:Button runat="server" Text="Server Prompt">
<Click OnEvent="ServerSidePromptCallback">

Nov 04, 2009, 11:14 AM
That works like a dream.

Thanks for the extra code illustrating the different methods it was really appreciated. I will be revisiting some of my previous MessageBox/Callback code to make improvements.