How to use MessageBox.Prompt with DirectMethod

  1. #1

    How to use MessageBox.Prompt with DirectMethod

    Hi,

    I'd like to use a messagebox.prompt and capture the value "text" in codebehind to send an email. How can I do this with DirectMethod?

    Please, coud you give an example?

    Tks,

    Oliver
  2. #2
    Hi,

    Here you are.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void Test(string buttonId, string text)
        {
            X.Msg.Alert("DirectMethod", buttonId + "<br/>" + text).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Prompt">
            <Listeners>
                <Click Handler="Ext.Msg.prompt('Title', 'Message', function (buttonId, text) {
                                    Ext.net.DirectMethods.Test(buttonId, text);
                                });" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Here you are.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void Test(string buttonId, string text)
        {
            X.Msg.Alert("DirectMethod", buttonId + "<br/>" + text).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Prompt">
            <Listeners>
                <Click Handler="Ext.Msg.prompt('Title', 'Message', function (buttonId, text) {
                                    Ext.net.DirectMethods.Test(buttonId, text);
                                });" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Hi Daniil,

    Thanks for the reply.

    Actually, I need to put the click handler in the codebehind, because I'm doing some actions in the code before show the Ext.Msg.Prompt. I tried to do that, but didn't work.

    Here my code, please help me to correct the call.

    Code to call the msg in codebehind:
    X.Msg.Prompt("Mensagem ao Colaborador", "Informe a mensagem a ser enviada ao colaborador", new JFunction { Handler = String.Format("Ext.net.DirectMethods.EnviarMensagem({0});",   Request.Params["text"]) }).Show();

        [DirectMethod]
        public void EnviarMensagem(string texto)
        {
            //here the action....
        }
  4. #4
    Example
    X.Msg.Prompt("Title", "Message", new JFunction() { Handler = "Ext.net.DirectMethods.DirectMethodName(text);" }).Show();
  5. #5
    Quote Originally Posted by Daniil View Post
    Example
    X.Msg.Prompt("Title", "Message", new JFunction() { Handler = "Ext.net.DirectMethods.DirectMethodName(text);" }).Show();
    Daniil,

    The code works but the directmethod is not call. The event is called by clicking in a button in the grid. Here the example:

    
                            <ext:CommandColumn Width="10" Header="" Align="Center" Sortable="false">
                                <Commands>
                                    <ext:GridCommand CommandName="Mensagem" Icon="Email" ToolTip-Text="Enviar Mensagem ao Colaborador" />
                                </Commands>
                            </ext:CommandColumn>
    
    
                    <DirectEvents>
                        <Command OnEvent="ShowDetails" >
                            <EventMask ShowMask="true" />
                            <ExtraParams>
                                <ext:Parameter Name="command" Value="command" Mode="Raw" />
                                <ext:Parameter Name="id" Value="record.id" Mode="Raw" />
                            </ExtraParams>
                        </Command>
                    </DirectEvents>
        protected void ShowDetails(object sender, DirectEventArgs e)
        {
            string id = e.ExtraParams["id"];
            string command = e.ExtraParams["command"];
    
            X.Msg.Prompt("Message", "Asked question", new JFunction() { Handler = "Ext.net.DirectMethods.EnviarMensagem(text);" }).Show();
    
            
        }
    
        [DirectMethod]
        public void EnviarMensagem(string texto)
        {
            X.Msg.Alert("Message", texto);
        }
    Can you help me? The problem is that is not called.

    Tks
  6. #6
    Confirmed, doesn't work with Handler.

    Please use Fn.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void TestDirectMethod(string text)
        {
            X.Msg.Alert("", text).Show();
        }
    
        protected void Prompt(object sender, DirectEventArgs e)
        {
            X.Msg.Prompt("Title", "Message", new JFunction() { Fn = "handler" }).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            var handler = function (buttonId, text) {
                Ext.net.DirectMethods.TestDirectMethod(text);
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Prompt" OnDirectClick="Prompt" />
    </body>
    </html>
  7. #7
    Quote Originally Posted by Daniil View Post
    Confirmed, doesn't work with Handler.

    Please use Fn.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void TestDirectMethod(string text)
        {
            X.Msg.Alert("", text).Show();
        }
    
        protected void Prompt(object sender, DirectEventArgs e)
        {
            X.Msg.Prompt("Title", "Message", new JFunction() { Fn = "handler" }).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            var handler = function (buttonId, text) {
                Ext.net.DirectMethods.TestDirectMethod(text);
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Prompt" OnDirectClick="Prompt" />
    </body>
    </html>
    Perfect! Thanks a lot!
  8. #8
    In 2.x there is not work.
    What should be corrected to work in 2.x version?
  9. #9
    Hi @ginsar,

    I think you just need to replace
    Ext.net.DirectMethods.TestDirectMethod(text);
    with
    App.direct.TestDirectMethod(text);
    P.S. This is not informative.
    In 2.x there is not work.
    Please always provide more details.
  10. #10
    Quote Originally Posted by Daniil View Post
    Hi @ginsar,

    I think you just need to replace
    Ext.net.DirectMethods.TestDirectMethod(text);
    with
    App.direct.TestDirectMethod(text);
    Thank you. It really works.

Similar Threads

  1. [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
  2. [CLOSED] Prompt before DirectEvent
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 05, 2010, 4:33 PM
  3. [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
  4. Custom Prompt MessageBox
    By EzaBlade in forum 1.x Help
    Replies: 2
    Last Post: Nov 04, 2009, 11:14 AM
  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

Tags for this Thread

Posting Permissions