[CLOSED] DirectEvents and CodeBehind

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] DirectEvents and CodeBehind

    Hi, I need to create a reusable custom control, with server-side actions (the control is a grid with a toolbar, the buttons are like save, new, and so on).

    I don't know how I can handle DirectEvents in a class and not on the same page.

    I want to recreate the example of your DirectEvents page using an external class even just for a button.

    DirectEvents.cshtml
    @page  "{handler?}"
    @model BBros.MySamples.Pages.DirectEventsModel
    @{
        ViewData["Title"] = "DirectEvent";
    }
    <ext-section target="Main">
        <ext-container id="myContainer" region="Center" scrollable="true" paddingAsString="30 20 30 50" model="Model.MyContainer">
        </ext-container>
    </ext-section>
    DirectEvents.cshtml
    using Ext.Net;
    using Ext.Net.Core;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using System;
    
    namespace BBros.MySamples.Pages
    {
        public class DirectEventsModel : PageModel
        {
            public Container MyContainer { get; set; }
    
            public void OnGet()
            {
                MyContainer = new Container();
                MyContainer.Items.Add(Samples.GetButton());
            }
        }
    }
    Samples.cs
    using Ext.Net;
    
    namespace BBros.MySamples
    {
        public class Samples
        {
            public static Button GetButton()
            {
                var b = new Button
                {
                    Id = "myCodeBehindButton",
                    Text = "Click me!"
                };
    
                //b.DirectEvents.Click.Event += myCodeBehindButton_Click();
                //HERE - What can I do?
    
                return b;
            }
       
        }
    }

    Is there an equivalent of this way?

    b.DirectEvents.Click.Event += myCodeBehindButton_Click()
    
    private void myCodeBehindButton_Click(object sender, DirectEventArgs e)
        {
                var msg = $"Server Time is { DateTime.Now.ToString("H:mm:ss tt") } :+1:";
                this.X().Toast(Mojee.Replace(msg));
                return this.Direct();
        }
    Thank you!
    Last edited by fabricio.murta; Jan 12, 2021 at 10:58 AM.

Similar Threads

  1. [CLOSED] DirectEvents : DirectEvents.Click.Before Wait message always show
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 27, 2015, 5:08 PM
  2. Replies: 1
    Last Post: Apr 03, 2014, 11:30 PM
  3. Replies: 10
    Last Post: Jan 30, 2014, 11:42 PM
  4. Replies: 2
    Last Post: Jul 15, 2013, 4:06 AM
  5. [CLOSED] DirectEvents call method codebehind
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Sep 05, 2011, 3:03 PM

Posting Permissions