Declare Click Event for Button created in Code Behind

  1. #1

    Declare Click Event for Button created in Code Behind

    Hello, I am creating a custom notification for the user when he enters my application, which has docked Items.

    This is my code

    X.Msg.Notify(new NotificationConfig()
                        {
                            Title = "Bienvenido " + user.FirstName + " " + user.LastName,
                            Height = 300,
                            Width = 400,
                            CloseVisible = true,
                            Closable = true,
                            AutoHide = true,
                            HideDelay = 30000,
                            Icon = Icon.Note,  PinEvent = "MouseOver",
                            DockedItems = {
                                new Label {  MarginSpec = "25 0 0 0",  Html = "<span style='font-size:18px'>Pestaña 'Dashboard' muestra número de sábanas solicitadas por mes</span>", Icon= Icon.ChartBar, IconAlign = Ext.Net.Alignment.Left },
                                new Button { UI=UI.Danger, Text="Ya no quiero ver este mensaje", Icon = Icon.ApplicationCascade, ClickEvent = "NoMoreButton"}
                            }
                            
                        }).Show();
    And I have my method

     private void NoMoreButton()
            {
                X.Msg.Notify("HOLA", "AMIGO").Show();
                // SOME MORE CODE
            }
    But this is not working... I am using properly the 'Click Event' property for my button when creating it ? I would appreciate help on how can I 'link' my method to this button created in code.

    Thanks!
  2. #2
    You are not defining the event method correctly.

    Please look at this example: Direct Events Overview. It shows you how to properly define a direct event that can be called from the page.

    Please take some time to browse the examples so you get an overview of what is showcased there. It can help you a lot when you have new questions. :)
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello and thanks again for your response.

    I've checked the examples and specifically took another look to that one you posted, but no C# code is used on creating the buttons on that example and I'm creating it on my code behind, and what I want to know is how to link my Code Behind generated button with a method on the same C# file, for when the user clicks on it.

    I hope I am being clear enough.

    Thanks and I'll wait for any response.
  4. #4
    Hello!

    Please look at how a DirectEvent method is defined in the examples. They are not private, and also they expect two arguments. You can't call them otherwise.

    If otherwise you want to use a DirectMethod, it also may not be private, but it may have arbitrary arguments as you use. In the other hand, you can't just bind it on events like Asp.NET actions, but call them on client-side Listeners (JavaScript) with App.direct.MethodName(arguments).

    If the examples are not enough I believe we would require you to provide us a working test case so we can run your sample here and give proper advice on how to make the click action to be handled.

    If in doubt on how to come up with a simple runnable example, please refer to these posts:
    - Forum Guidelines For Posting New Topics
    - More information required
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Apr 24, 2015, 11:20 AM
  2. Replies: 1
    Last Post: Jul 01, 2014, 2:37 PM
  3. Replies: 1
    Last Post: Feb 06, 2013, 5:39 PM
  4. Replies: 2
    Last Post: Dec 25, 2010, 11:07 AM
  5. [CLOSED] How to add event from code behind button click (DirectEventArgs)
    By mohan.bizbites in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 26, 2010, 5:58 AM

Tags for this Thread

Posting Permissions