1

如果我将事件添加到 RadDatePicker 控件,那么显然它可以工作

<telerik:RadDatePicker runat="server" ID="MyRadDatePicker" ClientEvents-OnDateSelected="clientEvent" />

. .

但是我的问题是,当 radDatePicker 位于自定义控件中并且该控件位于母版页上时,如何从母版页后面的代码中添加事件“ClientEvents-OnDateSelected”?

我试过这个,但它不会工作?

protected void Page_Load(object sender, EventArgs e)
{
UC1MyCustomControl.FindControl("MyRadDatePicker").ClientEvents-OnDateSelected="clientEvent";

}
4

2 回答 2

3

Cast the result of FindControl so you can access properties specific to RadDatePicker, and change the - in the attribute to .:

var datePicker = (RadDatePicker)UC1MyCustomControl.FindControl("MyRadDatePicker");
datePicker.ClientEvents.OnDateSelected = "clientEvent";

Instead of relying on FindControl, though, it might be better for the user control to expose the date picker as a public property:

// Inside the code-behind for the user control...
public RadDatePicker DatePicker
{
    get { return MyRadDatePicker; }
}

Using this property, the master page can access the date picker easily:

UC1MyCustomControl.DatePicker.ClientEvents.OnDateSelected = "clientEvent";
于 2013-08-15T14:27:06.807 回答
0

迈克尔斯回答+1。最好的方法是让自定义控件将 DatePicker 公开为属性,并且 Master Pager 可以使用该属性来设置所需的事件。

于 2013-08-17T18:59:36.817 回答