如何在ASP+中使用自訂的PAGELET

來源:互聯網
上載者:User
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>  

大家運行後,就可以看到這個的直接效果了



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.