如何属性的扩展类添加到文本框 [英] How to add an attribute to textbox in extension class

查看:90
本文介绍了如何属性的扩展类添加到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个文本框扩展类如下:

I've created an extension class for Textbox as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyApplication.App_Code 
{
    public class DateTextBox : TextBox
    {
        protected override void OnPreRender(EventArgs e)
        {
           //this is what iwant to do :
           //((TextBox)sender).Attributes.Add("placeholder", "dd/mm/yyyy");
           base.OnPreRender(e);
        }
    }
}

我需要的属性添加一个占位符在prerender TextBox控件,但我不知道如何引用发送文本框控件。

I need to add a "placeholder" attribute to the textbox control on prerender, but i'm not sure about how to reference the sender textbox control.

推荐答案

目前的情况是你的文本框。使用 this.Attributes

The current instance is your textbox. Use this.Attributes?

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.Attributes.Add("placeholder", "dd/mm/yyyy");
    }

这篇关于如何属性的扩展类添加到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆