This is a migrated thread and some comments may be shown as answers.

Date picker problem

8 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ali zubair
Top achievements
Rank 1
ali zubair asked on 08 Jun 2010, 06:07 AM
Hi All,

I have a problem. i have a page in which i have a button. and i have another page (user control) in which i have rad date picker named as rdDate. i show this page in div. now i want to do that by clicking on button i want to set date of rdDate. date which i provide. how can i do this.???


Please help. thanks

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jun 2010, 08:50 AM
Hello Ali,

You can achieve this, by getting reference to UserControl and then the embedded RadDatePicker by using FindControl() method; then set the SelectedDate property of RadDatePicker.

C#:
 
 protected void Button1_Click(object sender, EventArgs e) 
    { 
        UserControl uc = (UserControl)this.FindControl("UserControl_DatePicker1"); 
        RadDatePicker datepicker = (RadDatePicker)uc.FindControl("rdDate"); 
        DateTime dt = new DateTime(2009, 1, 24); 
        datepicker.SelectedDate = (DateTime)dt; 
    } 

Regards,
Shinu.


0
ali zubair
Top achievements
Rank 1
answered on 08 Jun 2010, 10:31 AM
Sorry i did not mention.. i want it from client side. like java script.
0
ali zubair
Top achievements
Rank 1
answered on 08 Jun 2010, 01:05 PM
pleaseeeeeeeeeeeeeeeee help.. i am badly struck.
0
Radoslav
Telerik team
answered on 08 Jun 2010, 04:26 PM
Hello Ali,

To achieve the desired functionality you could try setting the ClientID of the RadDatePicker to the javascript variable on the usercontrol's Page_Load event handler:
protected void Page_Load(object sender, EventArgs e)
{
     ScriptManager.RegisterStartupScript(Page, Page.GetType(), "registedID", "datepickerID = '" + RadDatePicker1.ClientID + "';", true);
}

Then when the button is clicked you could find the RadDatePicker and set the date:
<asp:Button ID="Button1" runat="server" Text="Set Date" OnClientClick="SetDate(); return false;" />
<telerik:RadCodeBlock runat="server" ID="sdf">
  <script type="text/javascript">
       var datepickerID;
       function SetDate()
        {
               var datePicker = $find(datepickerID);
                 datePicker.set_selectedDate(new Date());
            }
    </script>
 </telerik:RadCodeBlock>




Additionally I am sending you a simple example which demonstrates how to achieve the desired functionality.

Regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ali zubair
Top achievements
Rank 1
answered on 09 Jun 2010, 07:31 AM
Thanks for your reply. but "$find(datepickerID);" is not working for me. it returns null value.

Any other suggestion please.
0
Radoslav
Telerik team
answered on 09 Jun 2010, 03:36 PM
Hi Ali,

Could you please verify that on Page_Load you register startup script which set the RadDatePicker1.ClientID to the client datepickerID variable, like in my example. The $find(datepickerID); function will return null if you do not initialize the datepickerID via ScriptManager.RegisterStartupScript method in code behind.

Kind regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ali zubair
Top achievements
Rank 1
answered on 09 Jun 2010, 04:04 PM
yes sir. i confirm that i register it as you said. and when i debug javascript "datepickerID " does not return null or undefined. but when i use $find(datepickerID ) it returns null. i dont know why.

Please help... thanks
0
Radoslav
Telerik team
answered on 10 Jun 2010, 01:17 PM
Hello Ali,

Could you please post your aspx page within the code behind or open a support ticket and send us a small runnable project which demonstrates the issue. You could open a formal support ticket from your Telerik account and attach a ZIP file there.  In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.


All the best,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
ali zubair
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ali zubair
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or