ASP.net 2.0 server Control client Features

Source: Internet
Author: User

Most server controls that are applied at the presentation layer consist primarily of two parts: server-side and client functionality. Server-side functionality is always the core of server controls, and as technology develops, client functionality becomes increasingly important. Only two parts work together to create a powerful, interface-rich server control. This article discusses issues related to implementing client-side functionality in server controls, including overview of client functionality, implementation of simple client functionality, implementation of complex client functionality, and implementation of client file deployment.

1. Introduction to Client function

In Web programming, client functionality is traditionally the responsibility of Web page developers and is not encapsulated in server components. Asp. NET out of this category and enables server controls to emit client script, enabling server controls to combine client processing with server-side processing. Implementing client functionality is important to improve the interactivity and scalability of server controls. For example, Common TreeView, TabStrip, toolbar controls, and so on, these excellent server controls have strong interactivity and a rich user interface, and the implementation of these features is inseparable from client functionality.

The techniques for implementing client functionality are primarily client-side scripting (JavaScript, VBScript, etc.) and DHTML. Therefore, as a qualified developer, you must have the ability to skillfully apply these technologies. In addition, there is a way to combine client functionality with server controls. These include methods for implementing simple client functionality, implementing complex client functionality, and deploying client script files.

2. Realize simple client function

If the client-side functionality of a custom server control is simpler, for example, just a pop-up window or a change in the background color, and so on, it is implemented directly in the rendering of the control by not using a separate client script file for encapsulation. The key to its implementation is to add the appropriate client-side handlers in the control's attributes. The following example shows the control Myclickbutton derived from the System.Web.UI.WebControls.Button class, which provides an event handler for the client click event. Take a look at the following code:

public class MyClickButton : Button{
//相关代码
......
protected override void AddAttributesToRender(HtmlTextWriter writer) {
base.AddAttributesToRender(writer);
writer.AddAttribute("onclick", "window.confirm('谢谢您! ');");
}
}

If the reader has already read the previous article about the rendering of the control, it is easy to understand the above code. The above code overrides the AddAttributesToRender method, which defines an attribute named onclick for the Myclickbutton control, and its value indicates that a confirmation window that contains custom information is ejected from the client. If the client-side capabilities of the server controls developed by the reader are simple, you can try to implement them using the rewrite AddAttributesToRender method.

The following is an ASPX page source code created for use with the Myclickcontrol control.

<%@ Page Language = "C#" %>
<%@ Register TagPrefix="Custom" Namespace="MyControls" Assembly = "MyControls" %>
<html>
<body>
<form runat=server>
请点击下面的按钮
<Custom:MyClickButton Id = "demo" runat=server/>
<br>
</form>
</body>
</html>

When the user clicks on the Myclickcontrol control, it immediately pops up a confirmation window containing the message. Note that the pop-up confirmation window is not due to page return, but rather the result of the user firing the client handler. When the "OK" button is clicked, the page return will not occur.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.