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

[Solved] can't disable datepicker with Attributes.add

5 Answers 196 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sandra
Top achievements
Rank 1
Sandra asked on 23 Mar 2009, 04:03 PM
I am trying to disable the datepicker after a postback. 

For other objects I can use something like the following to hide a control:

nameofControl.Attributes.Add("STYLE", "Display: None")


Is there any code I can use to disable the radDatePicker after a post back?

I tried the following with no success.

nameOfDatePicker.Attributes.Add("dateInput", "disable")

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Mar 2009, 05:21 PM
Hello Sandra,

I would recommend you use the following approach:
RadDatePicker1.Enabled = False 

if you want to disable the nested DateInput only:
 RadDatePicker1.DateInput.Enabled = False 

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sandra
Top achievements
Rank 1
answered on 23 Mar 2009, 06:25 PM
That works, but then I can't disable it upon clicking another option button.

Here is what I am trying to do:
I need to enable or disable the raddatepicker based upon options selected.  But in order to not hit the server and be faster, I have a Javascript function that gets run when an option button is clicked.  This function enables/disables the raddatepicker

But then after a post back when they are submitting some information, the date picker is always enabled, when sometimes it should not be.  When I do as you suggest, it does correctly reset the datepicker to disabled after the postback.  But then when I click the option button again, the raddatepicker should become enabled, but it does not. 
0
Daniel
Telerik team
answered on 26 Mar 2009, 02:45 PM
Hello Sandra,

Another approach is shown below:
protected void DisableButton_Click(object sender, EventArgs e) 
    string myScript = "Sys.Application.add_load(function() { $find('" + RadDatePicker1.ClientID + "').set_enabled(false); });"
    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myScript", myScript, true); 

You can then enable/disable it on the client using the set_enabled javascript method.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sandra
Top achievements
Rank 1
answered on 30 Mar 2009, 09:18 PM
When I look up your suggestion on the internet, it says in order to do this, the control that I put it on the click even of, has to be on an update panel.  But I do not want it on an update panel as I am tring to only use Javascript for speed, or recapture the input after postback.  Is that true, that the control has to be on an update panel?

Also, I am having another problem with the line:

ScriptManager.RegisterStartupScript(Page,

typeof(Page), "myScript", myScript, true)

 


It gives an error:
'Is' expected
and the error is on the comma after the typeof(Page)

0
Daniel
Telerik team
answered on 03 Apr 2009, 12:44 PM
Hello Sandra,

When I look up your suggestion on the internet, it says in order to do this, the control that I put it on the click even of, has to be on an update panel.  But I do not want it on an update panel as I am tring to only use Javascript for speed, or recapture the input after postback.  Is that true, that the control has to be on an update panel?
No, you need the ScriptManager control only.

Also, I am having another problem with the line:
ScriptManager.RegisterStartupScript(Page,
typeof(Page), "myScript", myScript, true)

Please find my example, attached to this post.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
Sandra
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Sandra
Top achievements
Rank 1
Share this question
or