Calling Private method as Message box handler

  1. #1

    [CLOSED]Calling Private method as Message box handler

    Hi i am really impressed with the effort you guys have put into Ext.net .thumbs up ;)
    ok quickly getting into the example.

    Design of webpage.[ASP.NET]
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Sample Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="Samples">
            </ext:ResourceManager>
            <ext:Label ID="Label1" runat="server">
            </ext:Label>
            <ext:Button ID="Button1" runat="server" Text="Submit" Icon="ApplicationXpTerminal">
                <Listeners>
                <Click Handler="Samples.ShowMessage()" />
                </Listeners>
            </ext:Button>
        </div>
        </form>
    </body>
    </html>
    Code Behind: default.aspx.cs
     [DirectMethod]
            public void ShowMessage()
            {
                X.Msg.Confirm("Title", "This is some body", new MessageBoxButtonsConfig
                {
                    Yes = new MessageBoxButtonConfig { Handler = "Samples.ClickedYES()", Text = "YES" },
                    No = new MessageBoxButtonConfig { Handler = "Samples.ClickedNO()", Text = "NO" }
    
                }).Show();
            }
    
            [DirectMethod]
            public void ClickedYES()
            {
                Label1.Text = "You clicked YES";
            }
    
            [DirectMethod]
            public void ClickedNO()
            {
                Label1.Text = "You clicked NO";
            }
    as you see the
    ClickedYes() ,ClickedNo(), ShowMessage()
    are decorated with public Keyword. The code above works perfectly fine :D.
    1. But why can't i do the same when i set them to Private :confused:
    2. Is it possible to declare the handers as function rather than "string" if yes any samples?
    Last edited by deeptechtons; Dec 12, 2010 at 2:06 AM. Reason: changed title to solved,typo in title
  2. #2
    Hi,
    Thanks for the nice words:)

    Quote Originally Posted by deeptechtons View Post
    1. But why can't i do the same when i set them to Private :confused:?
    It's C# restrictions. ResourceManager control finds DirectMethods using reflection. So, it's possible to find only Public methods.


    Quote Originally Posted by deeptechtons View Post
    2. Is it possible to declare the handers as function rather than "string" if yes any samples?
    Please clarify what you mean?
  3. #3

    methods are enclosed in quotations

    Quote Originally Posted by Daniil View Post
    Hi,
    Thanks for the nice words
    It's C# restrictions. ResourceManager control finds DirectMethods using reflection. So, it's possible to find only Public methods.
    Please clarify what you mean?
    thanks for your answer daniil. this is what i meant by question 2. in code behind file you would note below code.
      public void ShowMessage()
           {
               X.Msg.Confirm("Title", "This is some body", new MessageBoxButtonsConfig
               {
                   Yes = new MessageBoxButtonConfig { Handler = "Samples.ClickedYES()", Text = "YES" },
                   No = new MessageBoxButtonConfig { Handler = "Samples.ClickedNO()", Text = "NO" }
     
               }).Show();
           }
    the method names are enclosed in quotations
    " and "
    Is there a method overload that takes a private method as parameter for the message box button handlers instead of declaring existing methods as string parameter.
  4. #4
    No, there is no such option.

    I'm not sure that this option would be not so useful. But maybe yes:)

    Anyway please note that there can be any JavaScript code.

    Example
    Yes = new MessageBoxButtonConfig 
    { 
        Handler = "alert('Hello! Clicked Yes.')", 
        Text = "YES" 
    }
    No = new MessageBoxButtonConfig 
    { 
        Handler = "someJsFunction('param1', 'param2')", 
        Text = "No" 
    }
    Yes = new MessageBoxButtonConfig 
    { 
        Handler = "Ext.net.DirectMethods.SomeDirectMethod('someParameter');", 
        Text = "YES" 
    }
    Last edited by Daniil; Dec 11, 2010 at 10:34 AM. Reason: Code formatting
  5. #5

    [CLOSED] Caling Private Methods as message box handler

    Yup now i understand the event model,thanks daniil

Similar Threads

  1. Replies: 3
    Last Post: Dec 28, 2011, 5:46 PM
  2. MVC - Render listener calling a javascript method
    By rsaldanhabr in forum 1.x Help
    Replies: 3
    Last Post: Aug 09, 2011, 10:12 PM
  3. Replies: 2
    Last Post: Apr 27, 2011, 2:58 PM
  4. Replies: 0
    Last Post: Apr 14, 2009, 6:10 PM
  5. calling ajax method from Javascript
    By vedagopal2004 in forum 1.x Help
    Replies: 1
    Last Post: Jan 21, 2009, 3:35 AM

Tags for this Thread

Posting Permissions