In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, Xiaobian introduces in detail how to use the event handling function of the Blazor component. The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the event handling function of the Blazor component" can help you solve your doubts.
Blazor components, provide event handling function, which is similar to using the client (Winform/Wpf) development, often used some similar: button (Button), input box (TextBox) used by some events, such as Click, DoubleClick, TextChanged and so on events allow us to deal with the corresponding logic in the background code.
Introduce the event
Event handling is also provided in the Razor component. For a HTML element attribute with a delegate type value named @ on {EVENT} (for example, @ onclick), the Razor component treats the value of this attribute as an event handler.
Call lamda expression
In the following example:
Input input box, add a text change event, then use the @ prefix, add an expression of lamda, and output a string "Hello"
For button, an onclick event has been added.
Use the code {} method
Similarly, we can add the method of C # to the code code block, and then apply it directly to our method name in the UI element.
Example: the following demonstrates a method in which the onclick event of a button button is bound to c #. When the button event is clicked, the bound c # code method is triggered:
@ code {public void Show () {/ / when the button is clicked, the following code}} asynchronous method will be executed
Event handling also supports asynchronous methods that return Task
Public async Task Show () {/ / when the button is clicked, the following code} method of the event parameter will be executed
If you need to handle some event parameters in UI in the method, you can add event parameters through the method, as shown below:
@ code {public async Task Show (MouseEventArgs e) {/ /...}} event parameter list
Methods for event parameters (overloaded)
When a method is bound to the same UI element, but the method is overloaded, we need to specify which method to call in the UI element, otherwise the compiler will not be able to recognize which method to use.
/ / call method with event parameters / / call method without event parameters @ code {/ / method without event parameters public void Show () {} / / method with event parameters public void Show (MouseEventArgs e) {}}
By default, if we just write an event-triggered method and know whether it has parameters, we don't need to pass parameters on the UI element binding method.
@ code {public void Show (MouseEventArgs e) {/ / when the button button is clicked, it will automatically pass the event parameters to e}} read here. The article "how to use the event handling function of Blazor components" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself before you can understand it. If you want to know more about related articles, Welcome to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.