Hello, in the client side javascript I would like to display the selected date in a textbox. When I read the oDatevalue and show it via the Alert function, I see the full date and time. How I can put this date (only) in the ASP.NET textbox named txtDate. The problem is that javscript doesn't know the field txtDate in the rendered page I think and I don't know to put it in the textbox. How to achieve this? Thanks in advance.Ps. the webcalendar is placed on a template field column from a standard ASP.NET webgrid. (Insert Item template)
<script type="text/javascript" id ="Infragistics">
function fDateClicked(oCalendar, oDate, oEvent) {
txtdate.text=oDate
</
}
arjanxp,
You will have to use javascript to break up the oDate variable into pieces (month, date, year), and then put the pieces together. For example:
var month = oDate.getMonth() + 1; //month is zero-based, so add 1 var day = oDate.getDate(); var year = oDate.getYear(); var text = month +"/" + day + "/" + year; var textbox = document.getElementById("TextBox1"); textbox.value = text;
So if you selected today's date, March 24, 2009 in the WebCalendar, the text in the TextBox will read "3/24/2009".
Hope this helps,
~Kim~
Hello Ho, thanks for you help so far. The script looks good only I receive an error:
'Can't Eval fDateClicked(oControl, ig_fireEvent.arguments[2], ig_fireEvent.arguments[3]);'
This I have in my .aspx page:
<script type="text/javascript" id="Infragistics"> function fDateClicked(oCalendar, oDate, oEvent) { //Add code to handle your event here. var month = oDate.getMonth() + 1; //month is zero-based, so add 1 var day = oDate.getDate(); var year = oDate.getYear(); var text = month + "/" + day + "/" + year; var textbox = document.getElementById("txtDate"); textbox.value = text; }
</script>
Thanks in advance.
I copy/pasted your javascript into my sample and wasn't able to reproduce the javascript errror you're encountering. That error usually indicates that there's a syntax error somewhere on your page. Can you post your entire code in your aspx page?
I'm not sure that's absolutely true, however I did some research prior to creating the sample for you and that was the only way I could find to get a reference to the control in the DetailsView's Templatefield.
Hello Kim, this is a nice workaround. Thank you very much. So the conclusion is that it's not possible to point directly to a field in a detailsview templatefield from within javascipt without this hiddenfield option?
I've created a sample that works around the limitation of not finding the txtDate textbox because it is in the DetailsView InsertItemTemplate. It uses a hidden field which contains the ClientID of the textbox. I am handling the DetailsView's server side DataBound event, checking to see what the CurrentMode is, and if it is in Insert mode, setting the value of the hidden field to the ClientID of the textbox.
It looks like the control can't be found b/c it is in the DetailsView InsertItemTemplate. If you used this code in a standard page even in a Master Page scenario, the code works fine. I'm doing some research in the Microsoft DetailsView to see if there is a way to get a reference to a control in its InsertItemTemplate; if I find anything I'll let you know.
Hello Kim, thanks for your answer. I think that your answer is correct, but I only receive a strange error : 'Name 'txtDate' is not declared'
The error points to the first lines of the code, I underlined them also, so the error points to the designer page I presume, but there are never controls present which stays in TemplateFields.I saw the same error description before on an AJAX page when it didn't recognize my ScriptManager. This had also to do with the masterpage scenario. Do you know a solution to this problem? Because when I build, it says no errors, but it shows 1 error as mentioned in the listbox. I can run my page but when I move to this page I get the error as well.When I comment out the whole javascript block, the error disappears. When I only comment the line with txtDate in it, the error remains...strange.
Thanks in advance!
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Masterpage.Master" CodeBehind="audit_add.aspx.vb" Inherits="AuditDB.audit_add" %>
<%@ Register assembly="Infragistics2.WebUI.WebDateChooser.v8.3, Version=8.3.20083.2039, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.WebSchedule" tagprefix="igsch" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" id="Infragistics">
function fDateClicked(oCalendar, oDate, oEvent) { var month = oDate.getMonth() + 1; //month is zero-based, so add 1 var day = oDate.getDate(); var year = oDate.getYear(); var text = month + "/" + day + "/" + year;// var textbox = document.getElementById("txtDate"); var textbox = document.getElementById("<%= txtDate.ClientID %>"); textbox.value = text; }