blazor-server-side

How do I set focus to a text box in Blazor

a 夏天 提交于 2020-12-12 04:03:45
问题 How do I set focus to a textbox in Blazor? So far the only way we have found is with JavaScript. 回答1: There is no other way to do it... You can use JSInterop to do this, as follows: <input type="text" @ref="myref"/> @code { private ElementReference myref; [Inject] IJSRuntime JSRuntime { get; set; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JSRuntime.InvokeVoidAsync("exampleJsFunctions.focusElement", myref); } } } JavaScript <script> window

How to pass a value from a page to the layout in Blazor?

早过忘川 提交于 2020-12-10 13:12:40
问题 I have a layout ( MainLayout.razor ), and it has a flag called ShowFooter . On some pages, I want to be able to set that flag to true , and some others to false . I haven't been able to find any clear instructions on how a page component can communicate with the layout. How should this be done in Blazor? Note: You might say I should have 2 layouts, one with and one without the footer, but that wouldn't really solve my problem, I want to be able to show and hide the footer at different times