Reputation: 9545
If I add the event to the RadDatePicker control then obviously it works
<telerik:RadDatePicker runat="server" ID="MyRadDatePicker" ClientEvents-OnDateSelected="clientEvent" />
. .
But My question is how do I add the event "ClientEvents-OnDateSelected" from the code behind of my master page when the radDatePicker is in a custom control and that control is on the master page?
I tried this but it wont work?
protected void Page_Load(object sender, EventArgs e)
{
UC1MyCustomControl.FindControl("MyRadDatePicker").ClientEvents-OnDateSelected="clientEvent";
}
Upvotes: 1
Views: 664
Reputation: 1626
+1 for Michaels answer. Best way is to for the custom control to expose the DatePicker as a property and the Master Pager can use that property to set the required events.
Upvotes: 0
Reputation: 55359
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";
Upvotes: 3