如何属性的扩展类添加到文本框

问题描述:

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

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