1. Component source file iposttest.cs
Function TogglesourceCodeRegion (RegionNumber)
{
VAR DivRegion = Document.getElementByid ('Region' RegionNumber);
Var DivRegionBlock = Document.getElementByid ('RegionBlock' RegionNumber);
IF (DivRegion.Style.Display == 'inline')
{
DivRegion.style.display = 'none';
DivRegionBlock.Style.display = 'inline';
}
Else
{
DivRegion.Style.display = 'inline';
DivRegionBlock.style.display = 'none';
}
}
script> 1 susking system;
2using system.Web.ui;
3using system.web.ui.webcontrols;
4USING System.comPonentModel;
5
6Namespace MyWebControl
7 {
8 ///
9 /// iposttest's summary description.
10 /// summary>
11 [DefaultProperty ("text"),
12 ToolboxData ("<{0}: iposttest runat = server> {0}: iposttest>")]
13 Public Class iposttest: System.Web.ui.WebControls.WebControl, iPostBackDataHandler
14 {
15 private string user;
16 private string pwd;
In one
18 // Control Name Settings
19 Private String Username
20 {
21 get
twenty two {
23 Return this.uniqueID ": user";
twenty four }
25}
26
27 Private String Pwdname
28 {
Get
30 {
31 Return this.uniqueid ": pwd";
32}
33}
34
35 // Public property
36 Public String UserValue
37 {
38 get
39 {
40 return user;
41}
42}
43
44 Public String PWDValue
45 {
46 get
47 {
48 return PWD;
49}
50}
51
52 ///
53 /// Present this control to the specified output parameter.
54 /// summary>
55 /// HTML writer to write param>
56 Protected Override Void Render (HTMLTextWriter Output)
57 {
58 //output.addattribute (HTMLTextwriterattribute.name ,this.Unique);
59 output.renderbegintag (htmltextwritertag.table);
60 output.renderbegintag (htmlTextwritertag.tr);
61 output.renderbegintag (htmlTextwritertag.td);
62
63 Output.addattribute (HtmlTextwriterattribute.Name, Username);
64 Output.Addattribute (HTMLTextWriterattribute.Value, ((user == null) String.empty: user);
65 Output.Addattribute (HTMLTextWriterattribute.Type, "Text");
66 output.renderbegintag (htmltextwritertag.input);
67 Output.renderendtag (); // Input
68
69 output.addattribute (htmltextwriterattribute.name, this.unique);
70 Output.addattribute (HtmlTextWriterattribute.Type, "Hidden");
71 Output.addattribute (HTMLTextwriterattribute.Value, "DD");
72 output.renderbegintag (htmltextwritertag.input);
73 Output.renderendtag (); // Input Hidden
74
75 output.renderbegintag (htmlTextwritertag.br);
76 output.renderendtag (); // br
77
78 Output.addattribute (HTMLTextwriterattribute.Name, PWDNAME);
79 Output.addattribute (HTMLTextWriterattribute.Value, ((PWD == NULL)? String.empty: PWD);
80 Output.Addattribute (HTMLTextWriterattribute.Type, "Text");
81 Output.renderbegintag (HTMLTextWritertag.input);
82 Output.renderendtag (); // Input
83
84 Output.renderendtag (); // TD
85 output.renderendtag (); // TR
86 Output.renderendtag (); // TABLE
87}
88 // IpostBackDataHandler Member
89
90 void ipostbackdatahandler.raisePostDataChangeDevent ()
91 {
92 // Todo: Add iposttest.raisePostDataChangeDevent implementation
93}
94
95 Bool ipostbackDataHandler.LoadPostData (String PostDataKey, System.Collections.Specialized.NameValueCollection Values)
96 {
97 // Todo: Add IPostTest.loadPostData Implement 98 User = VALUES [username];
99 PWD = VALUES [PWDNAME];
100 returnaf;
101}
102
103}
104}
105
2. Test method After compiling components, add the custom control toolbar, drag into the test page, add a Button button control, 3. Some conclusions must have a child control when there is multiple input child controls inside the component Name is this.uniqueID, so that the value of other child controls can be obtained. A. When I tried to load this.uniqueID to TABLE, I could not get the value of its sub-control INPUT. B. The above type is Hidden's INPUT, can be canceled, but this.UniqueID must be loaded on any other control, otherwise it does not get its value. I add a hidden type of INPUT, which is just to correspond to it, there is no other purpose. C. I really understand the web control, step by step, I don't know if you have encountered problems like me. I hope the master can give pointers grateful!