Custom Prompt MessageBox

  1. #1

    Custom Prompt MessageBox



    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.
  2. #2

    RE: Custom Prompt MessageBox



    
        <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>
  3. #3

    RE: Custom Prompt MessageBox



    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

Similar Threads

  1. Replies: 9
    Last Post: Nov 23, 2012, 3:13 AM
  2. [CLOSED] MessageBox prompt with required field
    By jchau in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 23, 2012, 4:39 PM
  3. [CLOSED] Prompt before DirectEvent
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 05, 2010, 4:33 PM
  4. [CLOSED] Messagebox prompt set cursor position to end
    By jchau in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 19, 2010, 11:40 PM
  5. Get the value from prompt dialog and save
    By CoolNoob in forum 1.x Help
    Replies: 5
    Last Post: Oct 23, 2009, 2:13 PM

Posting Permissions