ASP. NET dynamically adds control inheritance

Source: Internet
Author: User

 

As I talk more and more things in the background, the content and program history of this article become more and more, because this is not my original purpose,

So I will try to understand it in a simple and easy-to-understand way.

 

The benefits of inheritance are not mentioned here. It mainly demonstrates how to inherit from ASP. NET.

 

Generally, the pipeline is used to change the pipeline ASP. NET's existing controls, and I am most often used not in this regard, but to describe the development process of web standards. On the other hand, it is used to reduce my program development, the two goals are as follows,

In fact, it is all about the difficulty of reducing system complexity in the future.

 

It is especially important to develop a standardized process when multiple people are working together. Otherwise, anyone who has been programming with others knows that every developer, it takes a lot of time for you to understand each person's quota. The most troublesome thing is that each person develops a quota, it will also change with its growth. This means that every time you receive a program, whether or not you are the same person, you have to re-develop the code, the costs can be imagined.

 

The deal_Button_Click function is used in this program. This is a development process specification because our base program has completed the necessary processes, the people who want to accept it later can only develop according to our basic process. In this way, we can use this method, this method must be used to launch the application.

 

The principle of Program-less optimization is also quite easy to see. In this development mode, I have been using it for a long time, you don't have to think too much about it, especially if you want to think clearly at the beginning. This is a very difficult issue, which leads to the use of this development mode, the most simple way I suggest when using it is to integrate all the programs in my hands, you can achieve the goal of reducing program downloads. By reducing program downloads, you can attract other developers to use them together, everyone can discuss and refine them together.

 

The above method, of course, is only a matter of necessity, which makes it easy for the author to understand. In general cases, it is still necessary to provide in-depth support for members, first, we formulated the architecture and the definition-related concepts, and then developed them. There are a lot of deep discussions on this, and I don't need to add myself to this.

 

JS_Demo2Base.aspx.cs

1 using System;

2 using System. Data;

3 using System. Collections;

4 using System. Web. UI;

5 using System. Web. UI. WebControls;

6 using System. Web. UI. HtmlControls;

7 using System. Text;

8

9 public class JSDemoBase: System. Web. UI. Page {

10

11 protected HtmlGenericControl sourceTag;

12 protected Button _ myBtn;

13 protected TextBox _ myTB;

14

15 protected override void OnInit (EventArgs e)

16 {

17 base. OnInit (e );

18

19 Label message = new Label ();

20 message. ID = "Enter your words ";

21 sourceTag. Controls. Add (message );

22

23 _ myTB = new TextBox ();

24 _ myTB. ID = "input ";

25 // input. Text = val;

26 sourceTag. Controls. Add (_ myTB );

27

28_mybtn = new Button ();

29 _ myBtn. ID = "btnSayHello ";

30_mybtn. Text = "SayHello ";

31 sourceTag. Controls. Add (_ myBtn );

32

33 string val = Request. QueryString. Get ("val ");

34 deal_Button_Click (val );

35}

36

37 public virtual void deal_Button_Click (string value)

38 {

39}

40

41 public Button btnSayHello

42 {

43 get

44 {

45 return _ myBtn;

46}

47}

48 public TextBox input

49 {

50 get

51 {

52 return _ myTB;

53}

54}

55}

 

 

When writing a base program, if there is a server-side control that references asp.net, remember to define it first (the IDs and types must be consistent) at the beginning of the program ), for example, sourceTag in the above program. In this way, you can directly use the control in the program, just like the original asp.net program.

Www.2cto.com

JS_Demo2.aspx

1 <% @ Page Language = "C #" src = "./JS_Demo2Base.aspx.cs" Inherits = "JSDemoBase" %>

2

3 <script language = "C #" runat = "server">

4

5

6 public override void deal_Button_Click (string value)

7 {

8 input. Text = value;

9 if (value! = "" & Value! = Null)

10 btnSayHello. Attributes. Add ("OnClick", "return SetValue (" + input. ClientID + ");");

11 else

12 btnSayHello. Attributes. Add ("OnClick", "return GetOtherValue (" + input. ClientID + ");");

13}

14

15 </script>

16

17

18 <meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>

19

20 <body>

21 <script type = "text/javascript">

22 var myInput;

23 function GetOtherValue (ctrl ){

24 myInput = ctrl;

25 var hWnd = window. open ("JS_Demo.aspx? Val = "+ ctrl. value," _ blank ");

26 if (document. window! = Null )&&(! HWnd. opener ))

27 hWnd. opener = document. window;

28 return false;

29}

30 function SetValue (ctrl ){

31 window. opener. myInput. value = "Re:" + ctrl. value;

32 return false;

33}

34 </script>

35 <form runat = "server">

36

37

38

39 <p/>

40 <div id = "sourceTag" runat = "server">

41 </div>

42 <p/>

43 Xiaolong

44 </form>

45 </body>

46

 

 

 

~~~ A dragon (babydragoner )~~~

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.