All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP生成动态WAP页面_[PHP教程]
delphi事件的定义及作用
ASP.NET实例:在GridView使用HyperLinkField,属性的链接_[Asp.Net教程]
由浅入深学习动态网页制作PHP的编程与应用_php资料_编程技术
通过PHP连接My,SQL的两种方法简介_php资料_编程技术
ASP.NET Remoting体系结构(八)
讲解用ASP.NET编写串口程序的一点心得_.net资料_编程技术
ASP.NET一个最简单的会员登陆代码_[Asp.Net教程]
序列化和反序列化XML应用程序设置类_[Asp.Net教程]
[delphi语法4]数据类型:枚举类型
Reading number is top 10 pictures
Men's and women's orgasms
美女和狗狗1
人美胸美腿更美2
The real super beauty14
青春清纯美女大集合1
Small QiShu -- ShuangShuangPan2
如果没有好报,为什么要做好人?
战场废物1
如果我是导演...
10 powerless things in life
Download software ranking
Boxer vs Yellow3
Popkart Cracked versions Mobile phone games
Twenty piece of palm leaf
Ashlynn Video1
Boxer Classic video1
Unix video tutorial10
网络管理员第三版
双旗镇刀客A
Detective task-the top secret prostitution files
Boxer's Top ten classic battle10
归海一刀 published in(发表于) 2014/1/30 1:10:31 Edit(编辑)
扩展Label控件(1),-,实现回发(Postback)功能_[Asp.Net教程]

扩展Label控件(1),-,实现回发(Postback)功能_[Asp.Net教程]

扩展Label控件(1) - 实现回发(Postback)功能_[Asp.Net教程]

扩展Label控件(1) - 实现回发(Postback)功能 [源码下载]


Label控件既强大又好用。为了让它更强大、更好用,我们来写一个继承自Label的控件。

介绍
扩展Label控件:
通过注册HiddenField控件,使Label控件支持回发(Postback)功能

使用方法(设置属性):
EnablePostback - 是否启用Label控件的回发(Postback)
HiddenFieldPostfix - 使Label支持回发(Postback)的隐藏控件的后缀名


关键代码
ScriptLibrary.js
//----------------------------
// http://webabcd.cnblogs.com/
//----------------------------


function yy_sl_copyTextToHiddenField(source, destination)
{
///

将Label控件的的值赋给隐藏控件


document.getElementById(destination).value = document.getElementById(source).innerHTML;
}
SmartLabel.cs
using System;
using System.Collections.Generic;
using System.Text;


using System.Web.UI.WebControls;
using System.Web.UI;


[assembly: System.Web.UI.WebResource("YYControls.SmartLabel.Resources.ScriptLibrary.js", "text/javascript")]


namespace YYControls
{
/**////


/// SmartLabel类,继承自DropDownList
///

[ToolboxData(@"<{0}:SmartLabel runat='server'>")]
[System.Drawing.ToolboxBitmap(typeof(YYControls.Resources.Icon), "SmartLabel.bmp")]
public partial class SmartLabel : Label
{
/**////
/// 构造函数
///

public SmartLabel()
{


}


/**////


/// OnPreRender
///

/// e
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);


// 实现Label控件的回发(Postback)功能
ImplementPostback();
}
}
}


Property.cs
using System;
using System.Collections.Generic;
using System.Text;


using System.ComponentModel;
using System.Web.UI;


namespace YYControls
{
/**////


/// SmartLabel类的属性部分
///

public partial class SmartLabel
{
/**////
/// 使Label支持回发(Postback)的隐藏控件的后缀名
///

[
Browsable(true),
Description("使Label支持回发(Postback)的隐藏控件的后缀名"),
Category("扩展"),
DefaultValue("EnablePostback")
]
public virtual string HiddenFieldPostfix
{
get
{
string s = (string)ViewState["HiddenFieldPostfix"];


return (s == null) ? "EnablePostback" : s;
}
set
{
ViewState["HiddenFieldPostfix"] = value;
}
}


/**////


/// 是否启用Label控件的回发(Postback)
///

[
Browsable(true),
Description("是否启用Label控件的回发(Postback)"),
Category("扩展"),
DefaultValue(false)
]
public virtual bool EnablePostback
{
get
{
bool? b = (bool?)ViewState["EnablePostback"];


return (b == null) ? false : (bool)b;
}


set
{
ViewState["EnablePostback"] = value;
}
}
}
}


EnablePostback.cs
using System;
using System.Collections.Generic;
using System.Text;


using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;


namespace YYControls
{
/**////


/// SmartLabel类的属性部分
///

public partial class SmartLabel
{
/**////
/// 实现Label控件的回发(Postback)功能
///

private void ImplementPostback()
{
if (this.EnablePostback)
{
// 使Label支持回发(Postback)的隐藏控件的ID
string hiddenFieldId = string.Concat(this.ClientID, "_", HiddenFieldPostfix);


// 注册隐藏控件
Page.ClientScript.RegisterHiddenField(hiddenFieldId, "");


// 注册客户端脚本
this.Page.ClientScript.RegisterClientScriptResource(this.GetType(),
"YYControls.SmartLabel.Resources.ScriptLibrary.js");


// 表单提交前将Label控件的的值赋给隐藏控件
this.Page.ClientScript.RegisterOnSubmitStatement(this.GetType(),
"yy_sl_enablePostback",
string.Format("yy_sl_copyTextToHiddenField('{0}', '{1}')",
this.ClientID,
hiddenFieldId));
}
}


/**////


/// 获取或设置 YYControls.SmartLabel 控件的文本内容
///

public override string Text
{
get
{
try
{
if (this.EnablePostback && !string.IsNullOrEmpty(HttpContext.Current.Request[string.Concat(this.ClientID, "_", HiddenFieldPostfix)]))
{
// 隐藏控件的值
return HttpContext.Current.Request[string.Concat(this.ClientID, "_", HiddenFieldPostfix)];
}
else
{
return base.Text;
}
}
catch
{
return base.Text;
}
}
set
{
try
{
if (this.EnablePostback && !string.IsNullOrEmpty(HttpContext.Current.Request[string.Concat(this.ClientID, "_", HiddenFieldPostfix)]))
{
// 隐藏控件的值
base.Text = HttpContext.Current.Request[string.Concat(this.ClientID, "_", HiddenFieldPostfix)];
}
else
{
base.Text = value;
}
}
catch
{
base.Text = value;
}
}
}
}
}

作者:webabcd 来源:http://www.cnblogs.com/webabcd







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.