Hi
I have 2 webdate choosers in a page namely start date , end date. When the first time page loads start date highlights current date, month dropdown shows current month and year dropdown shows current year. First I changed the month to "March" and year to "2007". Then I have a button reset, there I set the value to null in server side as given below.
wbchStart.Value = null;
Using javscript in another page
Now the start date month, year dropdowns shows the value selected previously(March,2007). Same case for end date also. But I want to reset the month, year dropdowns to what it is displayed(September,2009) while pageload. I want the solution to reset in javascript also.
How can I do this? I am using c#. I have posted the code below. Let me know if you need any more information. I need immediate help in this regard. Thanks in advance.
<igsch:WebDateChooser Width="90px" ID="wbchStart" Section508Compliant ="true" runat="server" NullDateLabel="MM/DD/YYYY" CssClass ="date"> <ClientSideEvents InitializeDateChooser="InitProjectStartDateChooser" /></igsch:WebDateChooser >
function ResetDate() {
oStartTimeGenDateCt4.setValue(
null);
}
Hi Viktor,
Thanks. This is what I want.
Sridhar
Hi Sridhar,
I saw your codes, which set null to WebDateChooser, so I assumed that you want to reset (clear up) value in control.
If under reset you mean setting current current date instead of null, then you should use "new Date()" on client and "DateTime.Now", or "DateTime.Today", or "new DateTime()" on server. If you need to "reset" dateChooser on every load, then there is no need to do that on client and to process ClientSideEvents.InitializeDateChooser. It is enough to
protected void Page_Load(object sender, EventArgs e){ this.WebDateChooser1.Value = DateTime.Now;}
If you do that, then you do not need any server "reset " button. Though you may have reset button and within its click handler do exactly the same:
protected void ServerReset_Click(object sender,EventArgs e){ this.WebDateChooser1.Value = DateTime.Now;}
If you set value in WebDateChooser on client to current date, then drop-down will show current date too. If you set null to WebDateChooser on client, then to adjust visible date in drop-down calendar, you may use "Calendar" member variable.
function resetDateChooser(oDateChooser){ oDateChooser.setValue(new Date()); // null oDateChooser.Calendar.setVisibleMonth(new Date());}
I attached the screenshot with explanation for your reference.
Thanks.
Hi Viltor,
This solution also not working. I attached the sample site that I worked to you. I don't know whether you understand my question. I am telling it again.
"When the first time page loads datechooser highlights current date, month dropdown shows current month and year dropdown shows current year. Note: I set the nulldatelable as "MM/DD/YYYY"
I changed the month to "March" and year to "2007" and select the date as 3. Then I have a button reset using your code. The value set as null in code. Now please check the dropdowns it will show "March", "2007" (ie) previous selection. But I want to show as current month and current year in dropdowns as like page loads. I need to reset the dropdowns also to current date"
You can tell set current date while resetting but after reset it shows current date(Inside textbox) not MM/DD/YYYY. But I want to use as in pageloads while resetting.
Also tell me solution in c# code(in server side) for the same scenario. Use server side button reset by replacing input client button.
Thanks and regards
Hi Slidhar,
The setValue(null) should reset date in WebDateChooser on client. You may call that at any time: on init dateChooser, onload body and on any other event. Below is example:
<script type="text/javascript">function resetDateChooser(oDateChooser){ oDateChooser.setValue(null);}function resetValue(){ var dc = igdrp_getComboById('<%=WebDateChooser1.ClientID%>'); if(dc) resetDateChooser(dc);}</script><igsch:WebDateChooser ID="WebDateChooser1" runat="server" Value="2000-10-10"> <ClientSideEvents InitializeDateChooser="resetDateChooser"> </ClientSideEvents></igsch:WebDateChooser><input type="button" onclick="resetValue()" value="reset" />