asp+ asp+ 中提供了一種類似xml 的 代碼描寫方法,例如<asp:label id=test runat=server>
在本篇文章裡 我會給大家描述一下 如何 編寫自己的pagelet 例如:<asp888:myTestMenu
首先我們寫一個aspc 檔案,這個檔案必須在aspx 檔案中進行引用
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Drawing" %>
<script runat=server>
'建立公開變數
Public ForeColor As Color
Public BackColor As Color
Public Width As Unit
' 建立調用的函數和過程
Public Sub AddMenuItem(ByVal IN_Text As String, ByVal IN_URL As String)
Dim NewMenuItem As New TableCell
NewMenuItem.Text = "<a href='" & IN_URL & "'>" & IN_Text & "</a>"
mySubRow.Cells.Add(NewMenuItem) 'myMenu.Rows(0).Cells.Add(NewMenuItem)
End Sub
Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
myASPTable.BackColor = BackColor
myASPTable.Width = Width
myMenu.ForeColor = ForeColor
End Sub
</script>
<asp:Table border =1 id=myASPTable runat=server>
<asp:TableRow id=myRow1 runat=server>
<asp:TableCell id=myMainCell runat=server>
<!-- Begin nested menu table -->
<asp:Table border=1 id=myMenu runat=server
cellpadding=6
cellspacing=0>
<asp:TableRow id=mySubRow>
</asp:TableRow>
</asp:Table>
<!-- End nested menu table -->
</asp:TableCell>
</asp:TableRow>
</asp:Table>
好了,下面我們看看aspx 檔案
<%@ Page Language="vb" %>
<%@ Register TagPrefix="asp888" TagName="myTestControl" src="menu_control.aspc" %>
<html>
<head>
<script runat=server>
Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
menuControl1.AddMenuItem("豆腐技術站", "http://www.asp888.net")
If Page.IsPostBack
menuControl1.AddMenuItem(txtNewMenuText.Text, txtNewMenuLink.Text)
End If
End Sub
</script>
</head>
<body>
<asp888:myTestControl id="menuControl1" runat=server
BackColor = "gray"
Width="100%"
ForeColor="Silver" />
<form method=POST action=myMenuControl.aspx runat=server>
<p>
新的連接顯示:
<asp:TextBox id=txtNewMenuText Runat=server />
</p>
<p>
新的連接地址:
<asp:TextBox id=txtNewMenuLink Runat=server />
</p>
<p>
<input type=submit value="Submit" runat=server />
</form>
</p>
</body>
</html>
大家運行後,就可以看到這個的直接效果了