In the previous article, we implemented the drop-down box. The purpose of this chapter is to save the control property status.
Let's look at an example. The background code remains unchanged. We only need to change the code on the UI page. First, drag and drop two controls on the page. One is the control we want to develop, and the other is the Button.
<body> <form id= runat=> <XYB:TextEdit ID= DropDwonHeight= DropdwonWidth= runat=></XYB:TextEdit> <asp:Button runat= ID= Text= OnClick= /> </form></body>
We assign a value to the attribute in Page_Load. The Code is as follows:
Page_Load( (!= = btn_Click(
We ran and browsed it. The first result was indeed 100*100, but when we clicked the button, the length and width were reduced to 200, that is, the property value was not saved, now we only need to modify TextEdit. cs code, we use ViewState to save the control property status value
System.ComponentModel; ), Category() { ViewState[] == ? 1 : Convert.ToInt32(ViewState[ { ViewState[] = { ViewState[] == ? 1 : Convert.ToInt32(ViewState[ { ViewState[] = = = ==] = ; pnlDropDown.RenderControl(writer);
Re-generate the control and run it. OK. When the page is sent back, the property value remains unchanged.
ViewState is valid only on this page. For example, if there is A ViewState ["A"] On page A, ViewState ["A"] On page B is null.
Embedded resources of custom controls to predict the future. Please refer to the next decomposition. Stay tuned to me !!