分享
 
 
 

asp+语法介绍(五)服务器端编程控件

王朝asp·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

使用定制的服务器控件

在asp+中提供了45个已经做好了的服务器控件,我们可以将他们象黑盒子一样的使用。除此以外,开发者还可以使用任何第三方开发的服务器控件

在下面的例子中,我们要用到一个通过<acme:calendar runat=server>标签声明的组件,请注意,在文件的第一行必须使用<% Register %> 来声明 "Acme Xml "标签的的前缀"Acme".在asp+ 文件中,将会使用这个命名的服务器控件的类的实例。

<%@ Register TagPrefix="Acme" Namespace="Acme" %>

<html>

<head>

<link rel="stylesheet"href="intro.css">

</head>

<script language="VB" runat=server>

Sub SubmitBtn_Click(Sender As Object, E As EventArgs)

Message.Text = "Hi " & Name.Text & ", you selected: " & Category.SelectedItem.Text & " on: " & MyCal.Date

End Sub

</script>

<body>

<center>

<form action="intro7.aspx" method="post" runat="server">

<asp:adrotator AdvertisementFile="ads.xml" BorderColor="black" BorderWidth=1 runat="server"/>

<h3> Name: <asp:textbox id="Name" runat="server"/>

Category: <asp:dropdownlist id="Category" runat=server>

<asp:listitem >psychology</asp:listitem>

<asp:listitem >business</asp:listitem>

<asp:listitem >popular_comp</asp:listitem>

</asp:dropdownlist>

<asp:button type=submit text="Lookup" OnClick="SubmitBtn_Click" runat="server"/>

<p>

<Acme:Calendar id="MyCal" runat=server/>

<p>

<asp:label id="Message" runat="server"/>

</form>

</center>

</body>

</html>

声明Acme 的 文件

using System;

using System.Web;

using System.Web.UI;

using System.Collections;

namespace Acme

{

public class Calendar : Control, IPostBackEventHandler, IPostBackDataHandler

{

private String[] monthNames = new String[12];

private DateTime currentDate = DateTime.Now;

private String backColor = "#dcdcdc";

private String foreColor = "#eeeeee";

protected override void Init()

{

// Todo: We should remove the need to call this

Page.RegisterRequiresPostBack(this);

Page.RegisterPostBackScript();

currentDate = DateTime.Now;

// Todo: Hack needed because COOL doesn't support array initializers yet

monthNames[0] = "January";

monthNames[1] = "February";

monthNames[2] = "March";

monthNames[3] = "April";

monthNames[4] = "May";

monthNames[5] = "June";

monthNames[6] = "July";

monthNames[7] = "August";

monthNames[8] = "September";

monthNames[9] = "October";

monthNames[10] = "November";

monthNames[11] = "December";

}

protected override void LoadState(Object viewState)

{

// If we've done a post-back, the old date will be available to us

if (null != viewState)

{

currentDate = DateTime.Parse((String) viewState);

}

}

public void RaisePostBackEvent(String eventArgument)

{

//Page.Response.Write("RaisePostBackEvent Called!!!");

if (eventArgument == null)

{

return;

}

// Keep track of old date (for event firing purposes)

DateTime oldDate = currentDate;

// Todo: We should have post-back take two arguments: eventname and eventarguments

if (String.Compare("NavNextMonth", eventArgument, true) == 0)

{

currentDate = currentDate.AddMonths(1);

}

else if (String.Compare("NavPrevMonth", eventArgument, true) == 0)

{

currentDate = currentDate.AddMonths(-1);

}

else

{

int daySelected = Int32.Parse(eventArgument);

currentDate = new DateTime(currentDate.Year, currentDate.Month, daySelected);

}

}

protected override Object SaveState()

{

// Save CurrentDate out as view state for postback scenarios

return currentDate.ToString();

}

protected override void Render(HtmlTextWriter output)

{

//Response.Write(Page.Request.UserAgent);

if (Page.Request.UserAgent.IndexOf("MSIE 5.5") != -1)

RenderUpLevel(output);

else

RenderDownLevel(output);

}

protected void RenderUpLevel(HtmlTextWriter output)

{

output.WriteLine("<input name='" + UniqueID + "_CurrentDate' id='" + UniqueID + "_CurrentDate' type=hidden>");

output.WriteLine("<span id='" + UniqueID + "'></span>");

output.WriteLine("<script language=jscript>drawcalendar('" + UniqueID + "', '" + Int32.Format(currentDate.Year, null) + "/" + Int32.Format(currentDate.Month, null) + "/" + Int32.Format(currentDate.Day, null) + "');</script>");

}

protected override void PreRender()

{

String DHTMLFunction = "";

DHTMLFunction += "<script language='JavaScript'> \n";

DHTMLFunction += " function drawcalendar(calname, newDate) \n";

DHTMLFunction += " { \n";

DHTMLFunction += " var CurrentDate = new Date(newDate);\n";

DHTMLFunction += " var MonthArray = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');\n";

DHTMLFunction += " var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);\n";

DHTMLFunction += " var calText;\n";

DHTMLFunction += " calText = '<table bgcolor=#dcdcdc border=0 height=190 valign=top>';\n";

DHTMLFunction += " calText = calText + '<tr><td>';\n";

DHTMLFunction += " calText = calText + '<center>';\n";

DHTMLFunction += " calText = calText + \"<a href='javascript:drawcalendar(\\\"\" + calname + \"\\\", \\\"\" + CurrentDate.getFullYear() + \"/\" + CurrentDate.getMonth() + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n";

DHTMLFunction += " calText = calText + '<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>';\n";

DHTMLFunction += " calText = calText + ' <b>' + MonthArray[CurrentDate.getMonth()] + ' ' + CurrentDate.getFullYear() + '</b>';\n";

DHTMLFunction += " calText = calText + \" <a href='javascript:drawcalendar(\\\"\" + calname + \"\\\", \\\"\" + CurrentDate.getFullYear() + \"/\" + (CurrentDate.getMonth() + 2) + \"/\" + CurrentDate.getDate() + \"\\\")'>\";\n";

DHTMLFunction += " calText = calText + '<IMG SRC=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>';\n";

DHTMLFunction += " calText = calText + '</center>';\n";

DHTMLFunction += " calText = calText + '</td></tr>';\n";

DHTMLFunction += " calText = calText + '<tr valign=top><td valign=top>';\n";

DHTMLFunction += " calText = calText + '<table border=1 bgcolor=#eeeeee height=160>';\n";

DHTMLFunction += " calText = calText + '<tr height=20>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Sun </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Mon </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Tue </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Wed </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Thu </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Fri </td>';\n";

DHTMLFunction += " calText = calText + ' <td align=right width=23> Sat </td>';\n";

DHTMLFunction += " calText = calText + '</tr>';\n";

DHTMLFunction += " calText = calText + '<tr>';\n";

&

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有