(i). overview
Hyperlink does not have the Click event by default, overriding a hyperlink custom control.
Implementation principle:
The default hyperlink is the page that jumps to the click Request, and the hyperlink custom control eventually jumps to the requested page, but the period
Implemented a method of our own, we can add the function that we need in this method.
This example demonstrates the ability to count the number of clicks on this hyperlink. [Reference asp.net 2.0 advanced programming]
(ii). Code implementation
1. Custom control HyperLink.cs Code 1///
2///Author: [Chengking (Zhengjian)]
3///blog:http://blog.csdn.net/chengking
4///
5 Public partial class HyperLink:System.Web.UI.WebControls.HyperLink
6 {
7 Public HyperLink ()
8 {
9}
10
11///
12///Returns the name of the page to be counted [all clicks on this control will go through this total.aspx page]
13///
public string Totalpage
15 {
-Get
17 {
return "total.aspx";
19}
20}
21st
22///
23///1. When the method with the same name in the base class has a virtual flag, it is generally rewritten with override and polymorphic.
24///But when the base class does not have the virtual keyword, modifying the base class method with the new keyword does not have polymorphic functionality.
25///2. Modify NavigateUrl, will totalpage always as the target page;
26///and the user clicks on the target page as page parameter incoming
27///3. The method name must be NavigateUrl, because when the click event is executed, it automatically takes the value of the property name and makes the page jump
28///
The public new string NavigateUrl
30 {
To get
32 {
Return base. NavigateUrl;
34}
Set
36 {
Panax Notoginseng String strURL = "{0}?page={1}";
strURL = String.Format (strURL, totalpage, value);
Base. NavigateUrl = strURL;
40}
41}
42}
2. Total.aspx.cs code 1 for the page where the custom method is located///
2///Author: [Chengking (Zhengjian)]
3///blog:http://blog.csdn.net/chengking
4///
5 Public partial class Total:System.Web.UI.Page
6 {
7//Public statistics page, used to perform the click of the number of car pictures function method
8 protected void Page_Load (object sender, EventArgs e)
9 {
this. Custommethod ();
11
A string strobjectpage = request["page". ToString ();
Response.Redirect (Strobjectpage);
14}
15
16///
17///This method can be written like the onclick event code
18///
private void Custommethod ()
20 {
21//Do statistical functions, or other functions
//application["car_click_count"] = (int) application["Car_click_count"] + 1;
23}
24} (iii). Sample Code Downloads Http://www.cnblogs.com/Files/MVP33650/Total%20HyperLink%20count.rar (iv). Other custom controls related articles http://blog.csdn.net/ChengKing/category/288694.aspx
(i). overview
Hyperlink does not have the Click event by default, overriding a hyperlink custom control.
Implementation principle:
The default hyperlink is the page that jumps to the click Request, and the hyperlink custom control eventually jumps to the requested page, but the period
Implemented a method of our own, we can add the function that we need in this method.
This example demonstrates the ability to count the number of clicks on this hyperlink. [Reference asp.net 2.0 advanced programming]
(ii). Code implementation
1. Custom control HyperLink.cs Code 1///
2///Author: [Chengking (Zhengjian)]
3///blog:http://blog.csdn.net/chengking
4///
5 Public partial class HyperLink:System.Web.UI.WebControls.HyperLink
6 {
7 Public HyperLink ()
8 {
9}
10
11///
12///Returns the name of the page to be counted [all clicks on this control will go through this total.aspx page]
13///
public string Totalpage
15 {
-Get
17 {
return "total.aspx";
19}
20}
21st
22///
23///1. When the method with the same name in the base class has a virtual flag, it is generally rewritten with override and polymorphic.
24///But when the base class does not have the virtual keyword, modifying the base class method with the new keyword does not have polymorphic functionality.
25///2. Modify NavigateUrl, will totalpage always as the target page;
26///and the user clicks on the target page as page parameter incoming
27///3. The method name must be NavigateUrl, because when the click event is executed, it automatically takes the value of the property name and makes the page jump
28///
The public new string NavigateUrl
30 {
To get
32 {
Return base. NavigateUrl;
34}
Set
36 {
Notoginseng string strURL = "{0}?page={1}</