Sharepoint中DateTimeControl控件DateChanged事件实现(没有办法的办法)

前一段时间自定义一个Form页面,用到DateTimeControl控件,开始看了MSDN其DateChange事件可以这么使用:

Public eventDateChanged
Occurs when the date selected in the control changes.

自己傻傻的按照MSDN介绍就在后台代码中给加上

页面控件:

<SharePoint:DateTimeControl ID="dtStartDate" runat="server" AutoPostBack="true">
        </SharePoint:DateTimeControl>

后台代码:

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.dtStartDate.DateChanged += new EventHandler(dtStartDate_DateChanged);

        }

        protected void dtStartDate_DateChanged(object sender, EventArgs e)
        {
            //DateChanged之后处理代码
        }

不知道是MSDN骗俺还是俺功力不够,死活都不起作用。后来花了两三个小时找资料尝试各种各样的办法,

实在不行,只能用最后一招了:反编译Microsoft.SharePoint.dll看看DateTimeControl的结构,终于有了重大的发现

 protected override void CreateChildControls()
    {
        this.Controls.Clear();
        this.m_dateTextBox = new TextBox();
        this.m_dateTextBox.ID = this.ID + "Date";
        this.m_dateTextBox.MaxLength = 0x2d;
        this.m_dateTextBox.CssClass = this.CssClassTextBox;
        if (this.TabIndex > 0)
        {
            this.m_dateTextBox.TabIndex = this.TabIndex;
        }
        this.m_hoursDropDown = new DropDownList();
        this.m_hoursDropDown.ID = this.ID + "DateHours";
        if (this.TabIndex > 0)
        {
            this.m_hoursDropDown.TabIndex = this.TabIndex;
        }
        this.m_minutesDropDown = new DropDownList();
        this.m_minutesDropDown.ID = this.ID + "DateMinutes";
        if (this.TabIndex > 0)
        {
            this.m_minutesDropDown.TabIndex = this.TabIndex;
        }
        this.Controls.Add(this.m_dateTextBox);
        this.Controls.Add(this.m_hoursDropDown);
        this.Controls.Add(this.m_minutesDropDown);
        this.m_validatorRequired = new RequiredFieldValidator();
        this.m_validatorRequired.Display = ValidatorDisplay.Dynamic;
        this.m_validatorRequired.ErrorMessage = this.m_errorMessage_validatorRequired;
        this.m_validatorRequired.ControlToValidate = this.m_dateTextBox.ID;
        this.m_validatorRequired.Visible = this.IsRequiredField && !this.m_timeOnly;
        this.m_validatorRequired.EnableClientScript = this.IsRequiredField && !this.m_timeOnly;
        this.Controls.Add(this.m_validatorRequired);
        this.m_dateTextBox.TextChanged += new EventHandler(this.ChangesByUser);
        this.m_hoursDropDown.SelectedIndexChanged += new EventHandler(this.ChangesByUser);
        this.m_minutesDropDown.SelectedIndexChanged += new EventHandler(this.ChangesByUser);
    }
原来DateTimeControl中由一个TextBox和两个DropDownList组成的,只能采取以下代码实现了

        protected TextBox txtStartDate;
        protected DropDownList ddlStartDateHours;
        protected DropDownList ddlStartDateMinutes;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            txtStartDate = (TextBox)dtStartDate.FindControl("dtStartDateDate");        
            ddlStartDateHours = (DropDownList)dtStartDate.FindControl(dtStartDate.ID + "DateHours");
            ddlStartDateMinutes = (DropDownList)dtStartDate.FindControl(dtStartDate.ID + "DateMinutes");
            this.txtStartDate.TextChanged += new EventHandler(dtStartDate_DateChanged);
            this.ddlStartDateHours.AutoPostBack = true;
            this.ddlStartDateHours.SelectedIndexChanged += new EventHandler(dtStartDate_DateChanged);
            this.ddlStartDateMinutes.AutoPostBack = true;
            this.ddlStartDateMinutes.SelectedIndexChanged += new EventHandler(dtStartDate_DateChanged);
        }

后来一跑,还真的可以!第一次发贴,希望对大家有所帮助。

 

 

 

 

 

转载于:https://www.cnblogs.com/SeaBird/archive/2009/10/29/1592649.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值