Asp.net custom control development (4)-ViewState save control status

Source: Internet
Author: User

  • Summary

In the previous article, we implemented the drop-down box. The purpose of this chapter is to save the control property status.

  • Content

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.

  • Note:

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.

  • Next episode notice

Embedded resources of custom controls to predict the future. Please refer to the next decomposition. Stay tuned to me !!

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.