简体   繁体   中英

How to customize the Properties of usercontrol in c# asp.net?

I have usercontrol called as 'DateControl1' in which i have textbox and a calenderextender(ajax).I have written a property for my usercontrol as follows: public string DateFormat { get { return dateformat; } set { dateformat = value; } } when i assign the format in my cs file as DateControl1.DateFormat = "dd-mm-yyyy", then this dateformat must be assigned to the built-in property of Calenderextender.Can anyone please tell how to do this in c# asp.net?

For the first time, when your user control is going to consume the calendar extender at that time make sure to pass your property value to the calendar extender.

//something like this calext.DateFormat=DateFormat;

For an subsequent time, You can use the setter of your DateFormat property to set the property of calendar extender if the calendar extender has already been consumed.

//something like this
public String DateFomat{
get{return dateformat;}
set{dateformat=value; if(calext!=null) calext.DateFormat=dateformat;}
}

Thanks,
Pranav Kaushik (http://www.pranavkaushik.wordpress.com)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM