惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 花边软件,花边管理软件,服装(鞋)管理软件

让TextArea支持MaxLength的自定义文本框控件 让客户端js添加的Option也能保持在DropDownList TextBoxWatermark文本框水印效果 统一项目按钮外观 exe代替批处理文件添加注册表数据 系统权限设置 话说统一项目的Back(后退)控件 Css实现的颜色皮肤更换 sql注入 DataTable拷贝DataTable的数据 项目统一错误捕获 让每个页面的生命周期过程只产生一个Connection连接 一对多查询跟显示全路径Sql 多浏览器web开发界面的注意事项 - 花边软件,花边管理软件,服装(鞋)管理软件 - 博客园 如何将公共的JS变量跟方法集中放在同一个地方而且只加载一次 JS实现的HashTable类来记录删除的记录的ID跟Name 多语言站点 asp.net Web控件的设计时调试 正则表达式替换字符串 - 花边软件,花边管理软件,服装(鞋)管理软件 - 博客园
自定义文本框控件,包含Name跟ID
花边软件,花边管理软件,服装(鞋)管理软件 · 2008-07-11 · via 博客园 - 花边软件,花边管理软件,服装(鞋)管理软件

我们项目需要开发一个特殊的文本框,当点击文本框的时候弹出一个产品的窗口,选择一个产品之后,窗口关闭,把产品的名称跟产品的标识保存在文本框中,单击保存按钮处理单击事件的后台程序可以获取到选中产品的标识。
有了这样的需求后,让我们来开始设置这个控件。
第一步:在原有的Textbox进行扩展
public class SelectProductEditor : TextBox
{
}
第二步:就是要考虑如何保存选中产品的标识了。这里我们是动态添加一个TextBox,让它来保持选中产品的标识。
private TextBox txtProductID;
/// <summary>

/// 动态添加一个TextBox,让它来保持选中产品的标识
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
        base.OnInit(e);
        if (txtProductID == null)
        {
             txtProductID = new TextBox();               
        }
        txtProductID.ID = ClientID + "ID";
        txtProductID.Attributes["style"] = "display:none;";
}
第三步:就是如何得到动态生成的TextBox的Text。这里我们通过重载LoadPostData,获取动态添加TextBox的回发数值。
/// <summary>
///
/// </summary>
/// <param name="postDataKey"></param>
/// <param name="postCollection"></param>
/// <returns></returns>
protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string strTemp = postCollection[this.ClientID + "ID"];
            if(string.IsNullOrEmpty(strTemp) == false)
            {
                txtProductID.Text= strTemp;
            }
            return base.LoadPostData(postDataKey, postCollection);
        }
第四步:公开一个属性来获取产品标识的值
/// <summary>
/// 获取产品标识的值
/// </summary>
[DefaultValue(""), Localizable(true), Bindable(true, BindingDirection.TwoWay), Category("Appearance"), Description("TextBox_ProductID"), PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty), Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))
       ]
public string ProductID
{
     get
      {
                string text1 = this.txtProductID.Text;
                if (text1 != null)
                {
                    return text1;
                }
                return string.Empty;
       }
        set
        {
                this.txtProductID.Text = value;
          }
}

到这里,就可以实现一个文本框即可以获取产品的名称同时也可以获取产品的标识。