对ASP.NET自定义控件的内部实现较为失望~~~~
protected override void OnPreRender(EventArgs E)
{
StringBuilder DHTMLFunction = new StringBuilder();
DHTMLFunction.Append( "<script language='JavaScript'> \n" );
DHTMLFunction.Append( " function drawcalendar(calname, newDate) \n" );
DHTMLFunction.Append( " { \n" );
DHTMLFunction.Append( " var CurrentDate = new Date(newDate);\n" );
DHTMLFunction.Append( " var MonthArray = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');\n" );
DHTMLFunction.Append( " var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);\n" );
DHTMLFunction.Append( " var calText;\n" );
DHTMLFunction.Append( " calText = '<table bgcolor=#dcdcdc border=0 height=190 valign=top>';\n" );
DHTMLFunction.Append( " calText = calText + '<tr><td>';\n" );
DHTMLFunction.Append( " calText = calText + '<center>';\n" );
DHTMLFunction.Append( " calText = calText + \"<a href='javascript:drawcalendar(\\\"\" + calname + \"\\\", \\\"\" + CurrentDate.getFullYear() + \"/\" + CurrentDate.getMonth() + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n" );
DHTMLFunction.Append( " calText = calText + '<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>';\n" );
DHTMLFunction.Append( " calText = calText + ' <b>' + MonthArray[CurrentDate.getMonth()] + ' ' + CurrentDate.getFullYear() + '</b>';\n" );
DHTMLFunction.Append( " calText = calText + \" <a href='javascript:drawcalendar(\\\"\" + calname + \"\\\", \\\"\" + CurrentDate.getFullYear() + \"/\" + (CurrentDate.getMonth() + 2) + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n" );
DHTMLFunction.Append( " calText = calText + '<IMG SRC=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>';\n" );
DHTMLFunction.Append( " calText = calText + '</center>';\n" );
DHTMLFunction.Append( " calText = calText + '</td></tr>';\n" );
DHTMLFunction.Append( " calText = calText + '<tr valign=top><td valign=top>';\n" );
DHTMLFunction.Append( " calText = calText + '<table border=1 bgcolor=#eeeeee height=160>';\n" );
...............
看到了,内部最后还是通过javascript来实现,我不太喜欢写javascript,而且这里还不是直接写,类似这样的方法: DHTMLFunction.Append( "<script language='JavaScript'> \n" ); 把javascript当字符串,这样传到客户那是是javascript。原来在asp里也这么用过,这个方式及为不便。
不知在java里jsp在实现自定义控件类似功能时是用什么方法做的??听说有自定义的taglib,不过没具体用过,哪位给讲讲,是否是更好的实现方法???