欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery為用戶控件(ASCX)賦值與接口的應(yīng)用

 更新時(shí)間:2013年03月22日 14:35:10   作者:  
在網(wǎng)頁動(dòng)態(tài)加載用戶控件,并使用JQuery為來把網(wǎng)頁處理的值傳給用戶控件,此文利用了接口方面的知識(shí),感興趣的各位可以參考下哈

在本次演示中,使用了接口(interface),在網(wǎng)頁動(dòng)態(tài)加載用戶控件,并使用JQuery為來把網(wǎng)頁處理的值傳給用戶控件。

在面向編程中,較喜歡使用接口,認(rèn)為它能為不同對(duì)象之間處理到相同的行為。

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ISetValable
/// </summary>
namespace Insus.NET
{
public interface ISetValable
{
void SetValue(string value);
}
}

上面的接口,是想讓對(duì)象實(shí)現(xiàn)之后,能為控件賦值。

接下來,我們創(chuàng)建一件用戶控件,用戶控件的ascx放置一個(gè)Label標(biāo)簽,是將用來顯示從頁面?zhèn)鬟^來的值。真正環(huán)境中,也許不是簡(jiǎn)單的Label控件了,而是其它控件,或是對(duì)象了。

復(fù)制代碼 代碼如下:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="InsusUc.ascx.cs" Inherits="InsusUc" %>
<asp:Label ID="LabelMessage" runat="server" Text=""></asp:Label>

在ascx.cs代碼內(nèi),需要實(shí)現(xiàn)接口,把接口實(shí)現(xiàn)的方法所帶的參數(shù)賦給Label的Text.
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class InsusUc : System.Web.UI.UserControl,ISetValable
{
protected void Page_Load(object sender, EventArgs e)
{

}
public void SetValue(string value)
{
this.LabelMessage.Text = value;
}
}

OK,接口與用戶控件創(chuàng)建好了,需要?jiǎng)?chuàng)建網(wǎng)頁了。在.aspx.cs寫一個(gè)web method方法:

.aspx:

動(dòng)畫演示:

相關(guān)文章

最新評(píng)論