Jan 11, 2021, 10:27 AM
[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
Is there an equivalent of this way?
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.cshtmlusing 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.csusing 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 11:58 AM.