sharepoint datetime control does not display value on page load - sharepoint-2010

I am using SharePoint Datetime control in one of my asp.net custom pages. The problem is that I am trying to display the value from the sharepoint field in the datetime control, but it does not display it on page load. If I refresh the page then it displays it.
<SharePoint:DateTimeControl ID="dtdueDate" DateOnly="True" runat="server" />
DateTime dateTime = Convert.ToDateTime(item["DueDate"]);
((TextBox)(dtdueDate.Controls[0])).Text = dateTime.ToShortDateString();
Any help please?

You can use dtdueDate.LocalId property for formatting date, here: MSDN and Locale IDs, Input Locales, and Language Collections for Windows XP and Windows Server 2003 or create your own DatePicker Control, read here: SharePoint DateTime Control Date Format
Good luck!

It should be
dtdueDate.SelectedDate = Convert.ToDateTime(item["DueDate"] == null ? null : item["DueDate"].ToString());

Related

How to set string to datetime widget?

The title is self explanatory. I am having difficulties setting a string value to a date time widget.
XCP has a build in function stringToDate
which i use in these examples...
1. stringToDate('5-5-2009')
2. stringToDate('05-05-2009')
3. stringToDate('5/5/2009')
But non of them work. What am I missing here ?
Also i set the value of the widget in the behaviors tab of the date widget.
If you are talking about Date-Time Input widget then you need to use dateToString not stringToDate.
I figured out the issue. It's dependent to the format in which you save your date to string value. If we save the Date-Time Input widget value in this format:
dateToString('12-12-2018', 'm-d-Y')
then doing a :
stringToDate(savedvalue) will work only when the format saved was 'm-d-Y'. It wasn't working before because i saved it as 'd-m-Y'.

Formatting date in domForm.toJson in dojo

In my Web Application i have changed my dijit/form/DateTextBox date format using constraints="{datePattern:'MM/dd/yyyy'}" attribute,
But when i call the form containing the dijit/form/DateTextBox using domForm.toJson the format is changed to yyyy/dd/MM
why?
How to solve it
Dijit/Form/DateTextBox is a dojo/widget not dom.
domForm.toJson access Dom's value not Dijit widget's get('value') function which gives you a formatted output as you expect.
To get correct value - Use Dijit/Form and then use form.get("value")
Dijit Form

How to disable Telerik datetime picker in ASP.Net MVC 4?

I am trying to make datetime picker readonly. I found the following code in the internet
$("#RequestedDate").attr('disabled', true)
.next("span.t-select")
.children("span.t-icon-calendar").css("visibility", "hidden");
which works great but it reset datetime to minimun datetime.
You want to set the "readonly" attribute, not "disabled". If it's disabled the value won't be picked up.

FormBlock Server Control in Ektron

I am working in Ektron 8.6.
I have a FormBlock Server Control in my Template Page,It is having a DefualutFormID of a valid HTML form from workarea.The form in the workarea have got few form fields and their corresponding values.
While the template page is rendering I need to GET those form field values and re-set them with some other values.
In which Page –Cycle event I should do this coding?
I tried this code in Pre-Render Event,but I am unable to GET the value there,but I am able to set a value.
I tried SaveStateComplete event as well,no luck.
String s=FormBlock1.Fields["FirstName"].Value;
If(s=”some text”)
{
// Re-set as some other vale.
FormBlock1.Fields["FirstName"].Value=”Some other value”;
}
In which event I can write this piece of code?
Page_Load works fine for changing the value of a form field. The default behavior is for the Ektron server controls to load their data during Page_Init.
The real problem is how to get the default value. I tried every possible way I could find to get at the data defining an Ektron form (more specifically, a field's default value), and here's what I came up with. I'll admit, this is a bit of a hack, but it works.
var xml = XElement.Parse("<ekForm>" + cmsFormBlock.EkItem.Html + "</ekForm>");
var inputField = xml.Descendants("input").FirstOrDefault(i => i.Attribute("id").Value == "SampleTextField");
string defaultValue = inputField.Attribute("value").Value;
if (defaultValue == "The default value for this field is 42")
{
// do stuff here...
}
My FormBlock server control is defined on the ASPX side, nothing fancy:
<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>
And, of course, XElement requires the following using statement:
using System.Xml.Linq;
So basically, I wrap the HTML with a single root element so that it becomes valid XML. Ektron is pretty good about requiring content to be XHTML, so this should work. Naturally, this should be tested on a more complicated form before using this in production. I'd also recommend a healthy dose of defensive programming -- null checks, try/catch, etc.
Once it is parsed as XML, you can get the value property of the form field by getting the value attribute. For my sample form that I set up, the following was part of the form's HTML (EkItem.Html):
<input type="text" value="The default value for this field is 42" class="design_textfield" size="24" title="Sample Text Field" ektdesignns_name="SampleTextField" ektdesignns_caption="Sample Text Field" id="SampleTextField" ektdesignns_nodetype="element" name="SampleTextField" />

Dojo popup date picker

how do i make up the popup datepicker in dojo which should have seperate dropdown box for year,month..?
I dont think there is a date picker with separate year and month drop downs... I use dojo DateTextBox. The implementation is simple...
require(‘dijit.form.DateTextBox’);
<input type=”text” dojoType=”dijit.form.DateTextBox” name=”date” id=”date”/>
And why would you want separate year and month selectors when its easier for the user to select date from a calendar??? You can take out any part of the date on server side as you please once it is posted....
#Black Rider - it's better if you disable the ability for users to type in a date field. This way, you don't have to worry about validation if they just can select a date from the date picker.
I've had applications where users would need to select a date from many years in the past, e.g. 2002 or even the late nineties. What if you have an app where someone has to enter their birthday?
You could use a jQuery date picker instead, where you can easily add the year.
What Black Rider said is true (and DateTextBox is a great widget), HOWEVER there are also "mobile" dojo widgets that have what you are looking for:
1) "ValuePickerDatePicker" - http://dojotoolkit.org/reference-guide/1.9/dojox/mobile/ValuePickerDatePicker.html#dojox-mobile-valuepickerdatepicker
2) "SpinWheelDatePicker" (very iPhone-y) - http://dojotoolkit.org/reference-guide/1.9/dojox/mobile/SpinWheelDatePicker.html#dojox-mobile-spinwheeldatepicker