我为 Textbox 创建了一个扩展类,如下所示:
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);
}
}
}
我需要在预渲染的文本框控件中添加一个“占位符”属性,但我不确定如何引用发件人文本框控件。
最佳答案
您只需使用 this
:
this.Attributes.Add("placeholder", "dd/mm/yyyy");
关于c# - 如何在扩展类中向文本框添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27731602/