PDA

View Full Version : Custom Prompt MessageBox



EzaBlade
Nov 04, 2009, 7: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" }
}).Show();


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

jchau
Nov 04, 2009, 11: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>


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


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

EzaBlade
Nov 04, 2009, 12:14 PM
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.

RECLOSED