There are a lot of arguments about whether to use dynamic controls. I personally like to use this method for development,
On the one hand, it is very important for me to set parameters in a program. Otherwise, if the code is too long, you have to get an error, you need to find out which side is set everywhere.
On the other hand, it is conducive to the subsequent program abstraction. My habit is that after the program code is too large, I will start to think about what can be shared and then abstract it for use.
The following is a simple example of Hello World.
1 <% @ Page Language = "C #" AutoEventWireup = "True" %>
2
3 <script language = "C #" runat = server>
4
5 void SubmitBtn_Click (Object sender, EventArgs e)
6 {
7 Label message = new Label ();
8 message. Text = "Hello World !! ";
9 sourceTag. Controls. Add (message );
10}
11
12 </script>
13
14
15 <meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
16
17 <body>
18 <form runat = "server">
19
20
21
22 <asp: Button id = "Button1" Text = "Say Hello" OnClick = "SubmitBtn_Click" runat = "server"/>
23
24 <p>
25 <div id = "sourceTag" runat = "server">
26 </div>
27 <p>
28 Xiaolong
29 </form>
30 </body>
31
The execution screen is as follows:
In the future, I will take the time to sort out some advanced applications.
~~~ A dragon (babydragoner )~~~