Giter VIP home page Giter VIP logo

Comments (1)

Jurioli avatar Jurioli commented on May 28, 2024

There is no way to migrate it exactly the same as the original lifecycle.
It becomes an independent page lifecycle for each ControlComponent.

OnUpdate is the event that triggers the execution of StateHasChanged.

When clicking, only the page lifecycle of Button is executed and then other components update render are notified.

@page "/mypage"
@using System.Web.UI
@using System.Web.UI.WebControls
@inherits ControlComponent

<asp.TextBox ID="Val" TextMode="TextBoxMode.Date" @ref="this.myval">
</asp.TextBox>
<asp.Button _ref="() => this.button" Text="Add" OnClick="this.AddButton_Click" />
<h1>@res?.ToString()</h1>

<h1>
    <asp.Label _ref="() => this.msg" />
</h1>

@code {
    Button button = new Button();
    Label msg = new MsgLabel();

    protected override void OnInitialized()
    {
        this.Control.Init += Control_OnInit;
        this.Control.Load += Control_OnLoad;
        this.Control.PreRender += Control_OnPreRender;
        button.Init += Button_OnInit;
        button.Load += Button_OnLoad;
        button.PreRender += Button_OnPreRender;
        base.OnInitialized();
    }

    public void Control_OnInit(object sender, EventArgs e)
    {
        msg.Text += "Init (Control), ";
    }

    public void Button_OnInit(object sender, EventArgs e)
    {
        msg.Text += "Init (Button), ";
    }

    protected void Control_OnLoad(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            msg.Text += "First Load (Control), ";
        }
        else
        {
            msg.Text += "Postback Load (Control), ";
        }
    }

    protected void Button_OnLoad(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            msg.Text += "First Load (Button), ";
        }
        else
        {
            msg.Text += "Postback Load (Button), ";
        }
    }

    public void Control_OnPreRender(object sender, EventArgs e)
    {
        msg.Text += "Prerender (Control), ";
    }

    public void Button_OnPreRender(object sender, EventArgs e)
    {
        msg.Text += "Prerender (Button), ";
    }

    TextBox myval = null;
    DateTime? res = null;
    protected void AddButton_Click(object sender, EventArgs e)
    {
        res = Convert.ToDateTime(myval.Text);
        msg.Text += "Click Handler, ";
        // this.RequestRefresh();
        StateHasChanged();
    }

    protected override void OnUpdate(object sender, StateUpdateEventArgs e)
    {
        // how to use this?
        base.OnUpdate(sender, e);
        // dialogService.Alert("Update.");
    }

    public class MsgLabel : Label
    {
        protected override void Render(HtmlTextWriter writer)
        {
            this.Text += "Render (Label), ";
            base.Render(writer);
        }
    }
}

Init (Control), First Load (Control), Prerender (Control), Init (Button), First Load (Button), Prerender (Button), Render (Label),
Postback Load (Button), Click Handler, Render (Label), Prerender (Button), Render (Label),

from blazor.webform.components.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.