人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

對于.net的自定義控件(請各位大蝦指正)

對于.net的自定義控件(請各位大蝦指正)

更新時間:2022-06-06 文章作者:未知 信息來源:網絡 閱讀次數:

關于.net的自定義控件
一:談到自定義控件,就不得不說@Register(這玩藝具體怎么翻譯我也不知道,只好用E文,嘿嘿)。
1.@Register語法格式:
<%@Register tagprefix="tagprefix" Namespace="namespace" Assembly="assembly"%> or
<%@Register tagprefix="tagprefix" TagName="tagname" src="pathname"%>
2.屬性:
tagprefix:把別名和名稱空間連接在一起
tagname:把類名和名稱空間連接在一起
Namespace:哈哈,顧名思義把名稱空間和tagprefix連接在一起
src:用戶自定義控件的路徑
Assembly:我們與tagprefix聯系的名稱
注:Assembly的名稱不能包含已存在的文件名
(E文好的可看隨機文檔)
二:自定義控件的建立(.ascx)
 .net的自定義控件和asp里的.inc文件非常相似(包括功能也是),我們可以在里面使用html,更可以
連接數據庫等等,哎我怎么越說越不明白,還是看看例子吧:
第一個例子只是html文件:
Header.ascx
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td colspan="2" background="images/grid_background.gif" nowrap>
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td colspan="2">
<img src=http://cfan.net.cn/info/"images/most_secretive_place.gif">
</td>
<td align="right" nowrap>
<table cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td align="center" width="65">
<a href="Login.aspx" class="SiteLinkBold"><img src=http://cfan.net.cn/info/"images/sign_in.gif" border="0">
Sign In</a>
</td>
<td align="center" width="75">
<a href="OrderList.aspx" class="SiteLinkBold"><img src=http://cfan.net.cn/info/"images/account.gif" border="0">
Account</a>
</td>
<td align="center" width="55">
<a href="ShoppingCart.aspx" class="SiteLinkBold"><img src=http://cfan.net.cn/info/"images/cart.gif" border="0">
Cart</a>
</td>
<td align="center" width="65">
<a href="InstantOrder.asmx" class="SiteLinkBold"><img src=http://cfan.net.cn/info/"images/services.gif" border="0">
Services</a>
</td>
<tr>

</td>
<td width="10">
 
</td>
</tr>

</td>
</tr>
<tr>
<td colspan="2" nowrap>
<form method="post" action="SearchResults.aspx" id="frmSearch" name="frmSearch">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr bgcolor="#9D0000">
<td background="images/modernliving_bkgrd.gif">
<img align="left" src=http://cfan.net.cn/info/"images/modernliving.gif">
</td>
<td width="94" align="right" bgcolor="#9D0000">
<img src=http://cfan.net.cn/info/"images/search.gif">
</td>
<td width="120" align="right" bgcolor="#9D0000">
<input type="text" name="txtSearch" ID="txtSearch" SIZE="20">
</td>
<td align="left" bgcolor="#9D0000">
 <input type="image" src=http://cfan.net.cn/info/"images/arrowbutton.gif" border="0" id="image1" name="image1">
</td>
</tr>

</form>
</td>
</tr>

這里沒什么可說的,大家都非常熟.
第二個例子(和上一個當然不一樣了!):
Menu.ascx
<%@ Control Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

//*******************************************************
//
// The Page_Load event on this page is used to obtain
// from a database a list of all product categories
// and databind it to an asp:datalist control.
//
// To optimize performance, this user control is output
// cached (varying based on the categoryId and selection
// passed through the querystring.
//
//*******************************************************

void Page_Load(Object sender, EventArgs e) {
 
// Set the curent selection of list
String selectionId = Request.Params["selection"];

if (selectionId != null) {
MyList.SelectedIndex = Int32.Parse(selectionId);
}

// Obtain list of menu categories and databind to list control
IBuySpy.ProductsDB products = new IBuySpy.ProductsDB();

MyList.DataSource = products.GetProductCategories();
MyList.DataBind();
}

</script>

<table cellspacing="0" cellpadding="0" width="145" border="0">
<tr valign="top">
<td colspan="2">
<a href="default.aspx"><img src=http://cfan.net.cn/info/"images/logo.gif" border="0"></a>
</td>
</tr>
<tr valign="top">
<td colspan="2">
<asp:DataList id="MyList" runat="server" cellpadding="3" cellspacing="0" width="145" SelectedItemStyle-BackColor="dimgray" EnableViewState="false">
<ItemTemplate>
<asp:HyperLink class="MenuUnselected" id="HyperLink1" Text='<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>' NavigateUrl='<%# "productslist.aspx?CategoryID=" + DataBinder.Eval(Container.DataItem, "CategoryID") + "&selection=" + Container.ItemIndex %>' runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:HyperLink class="MenuSelected" id="HyperLink2" Text='<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>' NavigateUrl='<%# "productslist.aspx?CategoryID=" + DataBinder.Eval(Container.DataItem, "CategoryID") + "&selection=" + Container.ItemIndex %>' runat="server" />
</SelectedItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td width="10">
 
</td>
<td>
<br><br><br><br><br><br>
<a href="docs/docs.htm" target="_blank" class="SiteLink">IBuySpy Store<br>Documentation</a>
</td>
</tr>

三:我們建好了兩個.ascx文件,也就我們自己的控件,那怎么用呢?
 看下面:
default.aspx
<%@ Page Language="C#" %>
<%@ Register TagPrefix="IBuySpy" TagName="Menu" Src="_Menu.ascx" %>
<%@ Register TagPrefix="IBuySpy" TagName="Header" Src="_Header.ascx" %>
<script runat="server">

//*******************************************************
//
// The Page_Load event on this page is used to personalize
// the welcome message seen by returning IBuySpy users.
// It does this by retrieving a client-side cookie
// (persisted on the client in the Login.aspx and
// register.aspx pages) and updating a label control.
//
//*******************************************************

void Page_Load(Object sender, EventArgs e) {

// Customize welcome message if personalization cookie is present
if (Request.Cookies["IBuySpy_FullName"] != null) {
WelcomeMsg.Text = "Welcome " + Request.Cookies["IBuySpy_FullName"].Value;
}
}

</script>
<html>
<head>
<link rel="stylesheet" type="text/css" href="IBuySpy.css">
</head>
<body background="images/sitebkgrdnogray.gif" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td colspan="2">
<IBuySpy:Header ID="Header1" runat="server" />
</td>
</tr>
<tr>
<td valign="top" width=145>
<IBuySpy:Menu id="Menu1" runat="server" />
<img height="1" src=http://cfan.net.cn/info/"images/1x1.gif" width="145">
</td>
<td align="left" valign="top" width="*" nowrap>
<table height="100%" align="left" cellspacing="0" cellpadding="0" width="100%" border="0">
<tr valign="top">
<td nowrap>
<br>
<img align="left" width="24" SRC=http://cfan.net.cn/info/"images/1x1.gif">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="HomeHead">
<asp:Label id="WelcomeMsg" runat="server">Welcome to IBuySpy.com</asp:Label>
</td>
</tr>

</td>
</tr>

</td>
</tr>

</td>
</tr>

</body>
</html>

本鳥是邊學邊看,不足之處請大蝦指點(jiabaoxu@china.com),謝謝!!
CNet
2000.7.30




溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 福安市| 英德市| 广德县| 余江县| 伊宁县| 霸州市| 报价| 和田市| 色达县| 金沙县| 孝昌县| 枣强县| 桃源县| 台州市| 微博| 腾冲县| 清丰县| 克拉玛依市| 兴文县| 尉氏县| 永善县| 九寨沟县| 三门县| 海宁市| 万源市| 五家渠市| 武穴市| 荆门市| 改则县| 积石山| 正定县| 定兴县| 望奎县| 福鼎市| 延庆县| 聊城市| 安徽省| 陇西县| 宁南县| 新巴尔虎左旗| 上犹县|