Bazor-Blazor.WebForm.Components

[删除(380066935@qq.com或微信通知)]

Jurioli/Blazor.WebForm.Components: ASP.NET Web Forms System.Web.UI.WebControls Razor Components For Blazor WebAssembly, Blazor Hybrid, Blazor Server. (github.com)

Blazor.WebForm.Components

ASP.NET Web Forms System.Web.UI.WebControls Razor Components For Blazor WebAssembly, Blazor Hybrid, Blazor Server.

Demo: https://blazorwebformdemo.github.io/

@using System.Web.UI
@using System.Web.UI.WebControls
@page "/fetchdata-gridview"
@inherits ControlComponent
@inject HttpClient Http

<div>
    <h1>Weather forecast (GridView)</h1>
    <asp.Button Text="Load Data" OnClick="this.Button_Click"></asp.Button>
    <hr />
    <asp.Label @ref="this.label"></asp.Label>
    <br />
    <asp.GridView @ref="this.gridview" AutoGenerateColumns="false" CssClass="table" AllowPaging="true"
                  PageSize="2" OnPageIndexChanging="this.GridView_PageIndexChanging">
        <Columns>
            <asp.BoundField HeaderText="Date" DataField="Date" DataFormatString="{0:yyyy/M/d}"></asp.BoundField>
            <asp.BoundField HeaderText="Temp. (C)" DataField="TemperatureC"></asp.BoundField>
            <asp.BoundField HeaderText="Temp. (F)" DataField="TemperatureF"></asp.BoundField>
            <asp.BoundField HeaderText="Summary" DataField="Summary"></asp.BoundField>
        </Columns>
    </asp.GridView>
</div>

@code {
    private WeatherForecast[] forecasts;
    private Label label;
    private GridView gridview;

    protected async void Button_Click(object sender, EventArgs e)
    {
        forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");

        label.Text = DateTime.Now.ToString();

        gridview.PageIndex = 0;
        gridview.DataSource = forecasts;
        gridview.DataBind();

        this.RequestRefresh();
    }

    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gridview.PageIndex = e.NewPageIndex;
        gridview.DataBind();
    }

    public class WeatherForecast
    {
        public DateTime Date { get; set; }

        public int TemperatureC { get; set; }

        public string Summary { get; set; }

        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    }
}
  • Standard Toolbox
  • BulletedListDropDownListImageMapMultiViewTextBox
    ButtonFileUploadLabelPanelWizard
    CalendarHiddenFieldLinkButtonPlaceHolder
    CheckBoxHyperLinkListBoxRadioButton
    CheckBoxListImageLiteralRadioButtonList
    ComboBoxImageButtonLocalizeTable

  • Data Toolbox
  • DataListListView
    DataPagerRepeater
    DetailsView
    FormView
    GridView

  • Validation Toolbox
  • CompareValidatorValidationSummary
    CustomValidator
    RangeValidator
    RegularExpressionValidator
    RequiredFieldValidator

    Blazor Server

    Add CircuitHandler service to Program.cs

    builder.Services.AddScoped<CircuitHandler, ScriptManagerCircuitHandler>();
    using Microsoft.AspNetCore.Components.Server.Circuits;
    using System.Web.Hosting;
    
    namespace Server
    {
        public class ScriptManagerCircuitHandler : CircuitHandler
        {
            private readonly IServiceProvider _serviceProvider;
    
            public ScriptManagerCircuitHandler(IServiceProvider serviceProvider)
            {
                _serviceProvider = serviceProvider;
            }
    
            public override Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
            {
                ScriptManagerHost.AddScoped(_serviceProvider);
                return base.OnCircuitOpenedAsync(circuit, cancellationToken);
            }
    
            public override Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cancellationToken)
            {
                ScriptManagerHost.RemoveScoped(_serviceProvider);
                return base.OnCircuitClosedAsync(circuit, cancellationToken);
            }
        }
    }