Programming of ASP. NET components

Source: Internet
Author: User

How is event writing in ASP. NET component programming? First, let's take a look at the application of ASP. NET components:

Component code of ASP. NET component programming:

 
  1. UsingSystem;
  2. UsingSystem. Web. UI;
  3. UsingSystem. Web. UI. WebControls;
  4. UsingSystem. ComponentModel;
  5.  
  6. NamespaceNSEventStudy
  7. {
  8. Public Delegate VoidTwoEventHandle (IntFlag );
  9.  
  10. Public ClassEventStudy: System. Web. UI. WebControls. WebControl
  11. {
  12.  
  13. /// // ASP. NET Component Programming the first way to define the event //////////////////// 
  14.  
  15. Public EventTwoEventHandle TwoEvent;
  16.  
  17. Public VoidExecute (IntFlag)
  18. {
  19. TwoEvent (flag );
  20. }
  21.  
  22. /// // ASP. NET Component Programming second method for defining events //////////////////// 
  23.  
  24. Private Static Object_ Process =New Object();
  25. Public EventTwoEventHandle ThreeEvent
  26. {
  27. Add
  28. {
  29. Events. AddHandler (_ Process, value );
  30. }
  31. Remove
  32. {
  33. Events. RemoveHandler (_ Process, value );
  34. }
  35. }
  36.  
  37. Public VoidInnerExecute (IntFlag)
  38. {
  39. TwoEventHandle handle = (TwoEventHandle) Events [_ Process];
  40. If(Handle! =Null)
  41. {
  42. Handle (flag );
  43. }
  44. Else
  45. {
  46. This. RaiseBubbleEvent (This,Null);
  47. }
  48. }
  49.  
  50. Protected Override VoidRender (HtmlTextWriter writer)
  51. {
  52. Base. Render (writer );
  53. Writer. WriteLine ("I love you, China");
  54. }
  55.  
  56. }
  57. }

ASP. NET component programming event implementation test program:

 
  1. UsingSystem;
  2. UsingSystem. Collections;
  3. UsingSystem. ComponentModel;
  4. UsingSystem. Data;
  5. UsingSystem. Drawing;
  6. UsingSystem. Web;
  7. UsingSystem. Web. SessionState;
  8. UsingSystem. Web. UI;
  9. UsingSystem. Web. UI. WebControls;
  10. UsingSystem. Web. UI. HtmlControls;
  11.  
  12. NamespaceTestEvent
  13. {
  14. /// <Summary> 
  15. /// Summary of WebForm1. 
  16. /// </Summary> 
  17. Public ClassWebForm1: System. Web. UI. Page
  18. {
  19. ProtectedSystem. Web. UI. WebControls. Button Button1;
  20. ProtectedNSEventStudy. EventStudy EventStudy1;
  21.  
  22. Private VoidPage_Load (object sender, System. EventArgs e)
  23. {
  24. // Place user code here to initialize the page 
  25. }
  26.  
  27. # Code generated by region Web Form Designer 
  28. OverrideProtected VoidOnInit (EventArgs e)
  29. {
  30. // 
  31. // CODEGEN: This call is required by the ASP. NET Web form designer. 
  32. // 
  33. InitializeComponent ();
  34. Base. OnInit (e );
  35. }
  36.  
  37. /// <Summary> 
  38. /// The designer supports the required methods-do not use the code editor to modify 
  39. /// Content of this method. 
  40. /// </Summary> 
  41. Private VoidInitializeComponent ()
  42. {
  43. This. EventStudy1.ThreeEvent + =NewNSEventStudy. TwoEventHandle (This. Eventstudyincluthreeevent );
  44. This. EventStudy1.TwoEvent + =NewNSEventStudy. TwoEventHandle (This. EventStudy1_TwoEvent );
  45. This. Button1.Click + =NewSystem. EventHandler (This. Button#click );
  46. This. Load + =NewSystem. EventHandler (This. Page_Load );
  47.  
  48. }
  49. # Endregion 
  50.  
  51. Private VoidEventStudy1_TwoEvent (IntFlag)
  52. {
  53. This. Response. Write ("<Script> javascript: alert ('twoevent trigger ') </script>");
  54. }
  55.  
  56. Private VoidEventstudyincluthreeevent (IntFlag)
  57. {
  58. This. Response. Write ("<Script> javascript: alert ('threeevent trigger ') </script>");
  59. }
  60.  
  61. Private VoidButton#click (object sender, System. EventArgs e)
  62. {
  63. This. EventStudy1.Execute (6 );
  64. This. EventStudy1.InnerExecute (10 );
  65. }
  66. }
  67. }

The event compilation implementation in ASP. NET component programming will be introduced here, hoping to help you.

  1. ASP. NET Server Control View
  2. Detailed explanation of the lifecycle of ASP. NET components
  3. Analysis on Transmission Mechanism of ASP. NET Component Design
  4. Analysis on complex attributes and status management of ASP. NET Component Design
  5. Analysis of ASP. NET httpHandler

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.