I have an aspx page with a webdatetimeedit control on it. How do I get or set the value from JavaScript?
I need to do this:
It works fine with my textboxes and my dropdowns.
Here's my JavaScript code:
<script language="javascript" type="text/javascript"> var strInitialWebdatetimeeditValue = ""; var strInitialTextboxValue = ""; function SaveInitialValues() { strInitialMyDateTimeEditValue = document.getElementById('<%=MyDateTimeEdit.ClientID%>').text; strInitialMyTextboxValue = document.getElementById('<%=MyTextbox.ClientID%>').value; } function RestoreInitialValues() { document.getElementById('<%=MyDateTimeEdit.ClientID%>').value = strInitialMyDateTimeEditValue; document.getElementById('<%=MyTextbox.ClientID%>').value = strInitialMyTextboxValue; }</script>
<tr> <td> <igtxt:webdatetimeedit id="MyDateTimeEdit" runat="server" bordercolor="#000050" borderstyle="Solid" borderwidth="1px" usebrowserdefaults="False"> <ButtonsAppearance> <ButtonStyle BackColor="Control" BorderColor="Control" BorderStyle="Solid" BorderWidth="1px"> </ButtonStyle> <ButtonHoverStyle BackColor="#B8C0E0" BorderColor="#FFFFFF"> </ButtonHoverStyle> <ButtonPressedStyle BackColor="#8090B0" BorderColor="#FFFFFF"> </ButtonPressedStyle> </ButtonsAppearance> </igtxt:WebDateTimeEdit> </td></tr>
<tr> <td> <asp:TextBox ID="MyTextbox" TabIndex="3" runat="server" Width="244"></asp:TextBox> </td></tr>
Wow. That worked great. Thanks.
You need to get a reference to the WebDateTimeEdit control through its client-side object model (CSOM), rather than as an HTML element. This exposes the methods that can be used to get or set the text of th control (or to get its value as a date).
Here are modified versions of the two functions you've listed:
function SaveInitialValues() { strInitialMyDateTimeEditValue = igedit_getById('<%=MyDateTimeEdit.ClientID%>').getText(); strInitialMyTextboxValue = document.getElementById('<%=MyTextbox.ClientID%>').value; } function RestoreInitialValues() { igedit_getById('<%=MyDateTimeEdit.ClientID%>').setText(strInitialMyDateTimeEditValue); document.getElementById('<%=MyTextbox.ClientID%>').value = strInitialMyTextboxValue; }
You can get more information on the CSOM of all WebEditors from the WebEditors CSOM Overview (as exists in our online help documentation of NetAdvantage for Web Client 2009 Volume 1). This article links to documentation specific to individual WebEditor controls, including WebDateTimeEdit.