对ASP.NET自定义控件的内部实现较为失望~~~~

michaelpeng7799 2003-08-20 12:09:48
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,不过没具体用过,哪位给讲讲,是否是更好的实现方法???

...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
michaelpeng7799 2003-08-22
  • 打赏
  • 举报
回复
没人粘就结粘子了。
hj12 2003-08-20
  • 打赏
  • 举报
回复
jsp中的控件,可以是BEAN,也可以是自己定义的标签,用标签可以使页面简洁,也更适合
网页的设计者!但要在容器中配置,不知道.net是如何实现的讲一下,看看那种更好
flyycyu 2003-08-20
  • 打赏
  • 举报
回复
也是一样的,ASP.net控件的精华是服务器端回写!
michaelpeng7799 2003-08-20
  • 打赏
  • 举报
回复
有用过jsp相关功能的请粘一段有代表性的代码出来,对比一下。
gboy2003 2003-08-20
  • 打赏
  • 举报
回复
up
!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧