JQuery为用户控件(ASCX)赋值与接口的应用

夏夜,天上缀满了闪闪发光的星星,像细碎的流沙铺成的银河斜躺在青色的天宇上。大地已经沉睡了。我任了性,纵容思念开成一片海,定格成回忆里抹不去的风景。太阳把大海映红了,好像得大海披上了一层红纱。

在本次演示中,使用了接口(interface),在网页动态加载用户控件,并使用JQuery为来把网页处理的值传给用户控件。在面向编程中,较喜欢使用接口,认为它能为不同对象之间处理到相同的行为。

 
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);
}
}

上面的接口,是想让对象实现之后,能为控件赋值。

接下来,我们创建一件用户控件,用户控件的ascx放置一个Label标签,是将用来显示从页面传过来的值。真正环境中,也许不是简单的Label控件了,而是其它控件,或是对象了。


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

在ascx.cs代码内,需要实现接口,把接口实现的方法所带的参数赋给Label的Text.
 
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,接口与用户控件创建好了,需要创建网页了。在.aspx.cs写一个web method方法:

.aspx:

动画演示:

到此这篇关于JQuery为用户控件(ASCX)赋值与接口的应用就介绍到这了。唯一可以强横地霸占一个男人的回忆的,就是活得更好。更多相关JQuery为用户控件(ASCX)赋值与接口的应用内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
jQuery+Asp.Net实现省市二级联动功能的方法

详解JQuery Ajax 在asp.net中使用总结

jQuery实现金额录入框

jQuery实现倒计时跳转的例子

浅谈对Jquery+JSON+WebService的使用小结