Sharepoint datetime control, how to stop taking today date - asp.net

I have put SharePoint Date Time control in asp.net application page...Problem is by default it is taking Today date how to "stop tanking today date"...Thank you

I prefer using own control instead of sp date control.
var dateControl = new DateTimeControl();
dateControl.ID = "anyId";
dateControl.DateOnly = true;
dateControl.CssClassTextBox = "cssclass";
dateControl.LocaleId = Convert.ToInt32(SPContext.Current.RegionalSettings.LocaleId);
dateControl.OnValueChangeClientScript = "onApplyDateChangeValue(event)";
//if you want to set any value
dateControl.SelectedDate = DateTime.ParseExact("dateString", "dd.MM.yyyy",CultureInfo.InvariantCulture);
//Add to app page
"elementID".Controls.Add(dateControl);

It is working fine
write below code in side click function:
if (!spCal2.IsDateEmpty)
{
lblShowdtae.Text = dtSPdate.SelectedDate.ToString();
}

Related

Converting HijriCalendar to Gregorian in Xamarin forms

I am trying to convert HijriCalendar to Gregorian Calendar in Xamarin Forms app. However, it seems that Xamarin Android is not happy with it. I haven't test it in Xamarin iOS.
I am using code from Cannot convert from Hijri Date to Gregorian date (c#)
and I am getting below exception when instantiating the HijriCalendar object in line
DTFormat.Calendar = new System.Globalization.HijriCalendar(); //exception is thrown
{System.ArgumentOutOfRangeException: Not a valid calendar for the
given culture. Parameter name: value at
System.Globalization.DateTimeFormatInfo.set_Calendar
(System.Globalization.Calendar value) [0x00142]
I have checked Converting Dates between Calendars in Xamarin.Android solution, but that suggests another library which I am not interested to use.
I have changed the Linking properties in Android Project to None, Sdk Assemblyies Only, and Sdk & User Assembly but didn't worked. So, how to convert Gregorian Date to HijriDate in Xamarin forms?
I also added the following codes in OnCreate method in Xamarin Android from Thai crash: Not a valid calendar for the given culture
_ = new System.Globalization.GregorianCalendar();
_ = new System.Globalization.HijriCalendar();
_ = new System.Globalization.PersianCalendar();
_ = new System.Globalization.UmAlQuraCalendar();
_ = new System.Globalization.ThaiBuddhistCalendar();
Try to use System.DateTime:
Calendar hijiri = new HijriCalendar();
DateTime date = new DateTime(1442, 4, 15, hijiri);
Console.WriteLine(date.Year); // 2020
Console.WriteLine(date.Month);//11
Console.WriteLine(date.Day); // 30
Calendar gregorian = new GregorianCalendar();
DateTime d = new DateTime(2020, 11, 30, gregorian);
var year = hijiri.GetYear(d); //1442
var month = hijiri.GetMonth(d); //4
var day = hijiri.GetDayOfMonth(d); //15
and another way is using NodaTime.
I found simular problem on this link
https://github.com/xamarin/Xamarin.Forms/issues/4037
// These classes won't be linked away because of the code,
// but we also won't have to construct unnecessarily either,
// hence the if statement with (hopefully) impossible
// runtime condition.
//
// This is to resolve crash at CultureInfo.CurrentCulture
// when language is set to Thai. See
// https://github.com/xamarin/Xamarin.Forms/issues/4037
if (Environment.CurrentDirectory == "_never_POSSIBLE_")
{
new System.Globalization.ChineseLunisolarCalendar();
new System.Globalization.HebrewCalendar();
new System.Globalization.HijriCalendar();
new System.Globalization.JapaneseCalendar();
new System.Globalization.JapaneseLunisolarCalendar();
new System.Globalization.KoreanCalendar();
new System.Globalization.KoreanLunisolarCalendar();
new System.Globalization.PersianCalendar();
new System.Globalization.TaiwanCalendar();
new System.Globalization.TaiwanLunisolarCalendar();
new System.Globalization.ThaiBuddhistCalendar();
new System.Globalization.UmAlQuraCalendar();
}
Good luck!

Binding database data to a dropdownlist

I have been trying for a long time to fix the bugs I'm encountering with my dropdownlists in my project. I'm getting data this with at the moment and it's working fine:
using (InfoEntities ie = new InfoEntities())
{
var sqlddl = (from query in ie.Table_Customers
from q in ie.Accounting_PriceType
where query.TypeID == 1 && q.ID == 1
orderby query.Customers
select query).Distinct().ToList();
DropDownListCust.DataTextField = "Customers";
DropDownListCust.DataValueField = "ID";
DropDownListCust.DataSource = sqlddl;
DropDownListCust.DataBind();
}
Now when the user saves the data and opens the website again I need the saved value that was chosen on the dropdownlist earlier retreived. This also works fine but the problem is I'm getting duplicates. Anyways I'm doing it like this and I'm pretty sure I'm doing it wrong:
On the page load i load my dropdownlist to get all the items plus the following to get the saved value:
DropDownListCust.SelectedItem.Text = sql.Customers;
This makes my DDL very buggy, some items dissapear and also sometimes dupicated values. Can anyone please help? I'm using LINQ but I can use some other methods as long as it's fixed.
Cheers
I solved my problem like this:
DropDownList1.ClearSelection();
DropDownList1.Items.FindByText(sql.Customer).Selected = true;

How to disable/strikeout previous date using AjaxToolkit CalenderExtender in asp.net 3.5

In my project, I have used CalenderExtender (which comes with AJAX Control Toolkit) in my webpages.
Now, I want my calender to strikeout or disable the previous dates.
How can I do it in CalenderExtender?
Please use the js as follow to Strike Out the Past Days:
function checkDate(sender, args) {
if (sender._selectedDate < new Date()) {
alert("You cannot select a day earlier than today!");
sender._selectedDate = new Date();
// set the date back to the current date
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}
}

ASP.Net Control Visible=False Random Data Problem

Does anyone know of an issue with setting the Visible property of a control to false causing the value to change?
In the code below, the line:
control.Visible = dr.ParmDisplay;
On some servers, if the control is not visible it is not saving the value that was just set above it. We have a test server that this code works just fine, but we have a customer that the value is not saving. If the control is visible, it saves/shows/stores the value just fine on any server.
Is there some security patch that changes how this works??? I've Google'd it, and I don't find anything related to the visible property having this affect.
Here's the full code for this procedure:
protected void LoadReport()
{
dsReport.ReportParametersDataTable dt = objLoadXml.GetReportParameters(objReport.ReportName);
foreach (dsReport.ReportParametersRow dr in dt.Rows)
{
Control control = null;
IParm parameterControl = null;
if (dr.ParmType.ToUpper().StartsWith("DATERANGE"))
{
control = LoadControl("./UserControls/DateRange.ascx");
}
else if (dr.ParmType.ToUpper().StartsWith("DATE"))
{
control = LoadControl("./UserControls/Date.ascx");
}
else
{
control = LoadControl("./UserControls/Parameter.ascx");
}
control.EnableViewState = true;
parameterControl = (IParm)control;
parameterControl.ParmName = dr.ParmName;
parameterControl.ParmDescription = dr.ParmDescription;
parameterControl.ParmPickList = dr.ParmPickList.ToString();
if (dr["ParmDefaultValue"].ToString() != "")
parameterControl.ParmDefaultValue = dr.ParmDefaultValue;
control.Visible = dr.ParmDisplay;
PlaceHolder1.Controls.Add(control);
}
Thanks.
When you set a control to not visible, it does not get rendered to the browser. Therefore it will not be there on post back and the value won't make it back to the server.
If you need to persist the value w/out showing the control, store it directly in view state, or hidden input etc.

ASP Ajax Calendar Extender and displaying time

I am using the Ajax Control Toolkit Calendar Extender control. In some fields though I want to display the time along with the date. I have tried just setting the Format to "dd/MM/yyyy hh:mm:ss" but the time section gets wiped off. If the user wants to change the time section they can do it manually, the calendar drop down is only used for changing the date part.
Are there any workarounds or alternatives to get this working?
I have a similar issue and I'm planning to use a Date field and an associated time dropdown (in 1/2 hour increments). User sets the date in the date field, optionally using the calendar control, and pulls down to a valid time. I plan to have one selection in the time drop down be a "don't care" in case it an "all day" event.
[EDIT] I found this jquery plugin that I may end up using. I also found a link to Gaia DateTimePicker in the answers to this post (which now looks to be deleted, probably because the OP was asking for WPF controls, not web controls).
The Ra-Ajax Calendar is coming out with TIME support this upcoming Friday (28th of Nov. 2008) and it's LGPL licensed...
Based on CalendarExtender, you can set the format as "MM/dd/yyyy". After the user select the date in calendar, it will return 04/28/2009 for example. In the date selected event, you can append the current time after the date returned.
OnClientDateSelectionChanged="dateselect"
function dateselect(ev)
{
var calendarBehavior1 = $find("Calendar1");
var d = calendarBehavior1._selectedDate;
var now = new Date();
calendarBehavior1.get_element().value = d.format("MM/dd/yyyy") + " "+now.format("HH:mm:ss")
}
The only way to add time component to the AjaxControlToolKit CalendarExtender, is to append it using OnClientDateSelectionChanged and JavaScript.
<ajaxToolkit:CalendarExtender ID="ce1" runat="server" PopupButtonID="calImg" Enabled="true" Format="dd/MM/yyyy" TargetControlID="txtLeft" PopupPosition="TopRight" OnClientDateSelectionChanged="AppendTime"></ajaxToolkit:CalendarExtender>
and
<script language="javascript" type="text/javascript">
//this script will get the date selected from the given calendarextender (ie: "sender") and append the
//current time to it.
function AppendTime(sender, args) {
var selectedDate = new Date();
selectedDate = sender.get_selectedDate();
var now = new Date();
sender.get_element().value = selectedDate.format("dd/MM/yyyy") + " " + now.format("hh:mm tt");
}
</script>

Resources