是否将CalendarExtender动态添加到Textbox子类服务器控件? [英] Dynamically add CalendarExtender to Textbox subclass server control?

查看:101
本文介绍了是否将CalendarExtender动态添加到Textbox子类服务器控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个从TextBox继承的服务器控件,该控件将自动具有 CalendarExtender 附加到它。是否可以这样做,还是我的新控件需要继承自CompositeControl?我已经尝试过前一种方法,但不清楚在控件生命周期的哪一部分中应该创建CalendarExtender的新实例,以及应将其添加到哪个控件集合中。我似乎无法将其添加到Page或Form的控件集合中,如果将其添加到(TextBox)控件的集合中,则无法获得弹出日历功能。

I'm trying to create a server control, which inherits from TextBox, that will automatically have a CalendarExtender attached to it. Is it possible to do this, or does my new control need to inherit from CompositeControl instead? I've tried the former, but I'm not clear during which part of the control lifecycle I should create the new instance of the CalendarExtender, and what controls collection I should add it to. I don't seem to be able to add it to the Page or Form's controls collection, and if I add it to the (TextBox) control's collection, I get none of the pop-up calendar functionality.

推荐答案

我不久前在一个项目中完成了此任务。为此,我创建了一个包含TextBox和CalendarExtender的CompositeControl。

I accomplished this in a project a while back. To do it I created a CompositeControl that contains both the TextBox and the CalendarExtender.

CreateChildControls 方法中CompositeControl我使用类似于以下代码:

In the CreateChildControls method of the CompositeControl I use code similar to this:

TextBox textbox = new TextBox();
textbox.ID = this.ID + "Textbox";
textbox.Text = this.EditableField.TextValue;
textbox.TextChanged += new EventHandler(HandleTextboxTextChanged);
textbox.Width = new Unit(100, UnitType.Pixel);
CalendarExtender calExender = new CalendarExtender();
calExender.PopupButtonID = "Image1";
calExender.TargetControlID = textbox.ID;
this.Controls.Add(textbox);
this.Controls.Add(calExender);

当然,请确保包含此CompositeControl的表单具有工具箱脚本管理器。

Of course make sure that the form containing this CompositeControl has a toolkit script manager.

这篇关于是否将CalendarExtender动态添加到Textbox子类服务器控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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