Development of the textarea control in mobile Web application (1)

Source: Internet
Author: User
In fact, I don't want to write this article, but I 've been tossing it for a long time, alas... write down and give yourself a summary. in use. net when developing mobile web, it is obvious that a control is very useful, but. net does not provide, that is, textarea, multi-line input. I Googled and found an article about how to customize this control. The original Article is here. in addition, there is a ready-made control available for download on the Asp.net website. For details, refer to here. you can go directly to the two links I provided above, or go on to look at them. I will briefly introduce code development, and then focus on the configuration issues. this is rarely mentioned in the previous article. to develop a custom control, you need to implement two classes by yourself. One is the control class that you want to derive from a control, and the other is the adapter class that is responsible for render the control ). first, we implement a class called multilinetextbox, which is derived from the textbox class. It is relatively simple to add two more attributes: Cols and rows. the Code is as follows:

Public class multilinetextbox: system. Web. UI. mobilecontrols. textbox
{

Private int _ Cols = 0;
Public int Cols
{
Get {return this. _ Cols ;}
Set {This. _ Cols = value ;}
}
Private int _ rows = 0;
Public int rows
{
Get {return this. _ rows ;}
Set {This. _ rows = value ;}
}
}

Of course, you can also put two attribute values in viewstate as in a foreigner's article. If you do not intend to disable viewstate in your program, this should be a better solution. step 2: implement a multilinetextboxadapter class derived from controladapter, and reload an attribute and a method. the Code is as follows: public class htmlmultilinetextboxadapter: system. web. UI. mobilecontrols. adapters. controladapter
{
Protected New multilinetextbox Control
{
Get {return (multilinetextbox) base. Control ;}
}
 
Public override void render (htmltextwriter writer)
{
Writer. writebegintag ("textarea ");

String rendername;
If (device. requiresattributecolonsubstitution)
{
Rendername = control. uniqueid. Replace (':',',');
}
Else
{
Rendername = control. uniqueid;
}
Writer. writeattribute ("name", rendername );
Writer. writeattribute ("Cols", Control. cols. tostring ());
Writer. writeattribute ("rows", Control. Rows. tostring ());

Writer. Write ("> ");
Writer. Write (control. Text );
Writer. writeendtag ("textarea ");

}
}

 

The overload of attribute control indicates that the class I want to manage is multilinetextbox. the reload render method is specific to how to express this control on the page, that is, to output a textarea tag. step 3: Modify the web. config to add support for the device. I am stuck in this step... submit it first, and then discuss it later.

 

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.