Can I start the Calendar Control for asp.NET to be a future date? - asp.net

I need to have the Calendar Control start 36 hours after the current date. How would I do that?
I have a form that requires that the future date has to be at least 36 hours from the current date in the order for the workers involved to be able to complete the task.
EDIT: Thanks everyone for helping with my question. I've created a solution that will allow me to check values and keep the form from processing:
Protected Sub calPickupDate_SelectionChanged(sender As Object, e As System.EventArgs) Handles calPickupDate.SelectionChanged
If calPickupDate.SelectedDate < Today.AddHours(36) Then
ASPNET_MsgBox("You must leave at least 36 hours for procesing of your order.")
txtPickupDate.Text = ""
Else
txtPickupDate.Text = calPickupDate.SelectedDate.ToString("MM/dd/yyyy")
End If
End Sub
So, how do I close out the question?

Dim DateTimePicker As New DateTimePicker
DateTimePicker.MinDate = Date.Now.AddHours(36)
DateTimePicker.Value = Date.Now.AddHours(36)

add below code on your form load.
calPickupDate.MinDate = Date.Now.AddHours(36)
hope this will help you.

I assume you mean a date picker type of "calendar" and not a calendar. If so, you are dealing with a data validation issue.
There are different ways to validate the input. The quickest is server side only. If the user picks the wrong date, you tell him and he can pick ad nauseum until he gets a clue. Not the best UI, but it works.
Since the data ends up in a textbox, you can set javaScript on the textbox to remove wrong dates and show an "error" label with a message like "date/time must be X". If you can use AJAX, there are some pretty neat samples here.

Related

What is the best way to get the date and time in server side?

I'm developing an asp.net mvc3 project. I have a trouble in this problem that I encounter. I will give a scenario so that it will understand well.
Scenario:
I have 2 PC (PC1(server) and PC2(client)). For example both two PC has different date and time let say for PC1 is +8GMT Date 8/10/2016 and for PC2 +8GMT Date 8/9/2016. I am using the PC2 the client and i'm using a code for getting the time is DateTime.Now(); in my controller and the time is display in label in one of my views. I tried to adjust the Date and Time of the PC2 the label for displaying t he time also change. What I want is even I change the Date and Time in PC2 it won't affect/change the displayed Date and Time in my label it will stick on what the Date and Time in the PC1.
This scenario is i'm using/testing the publish project
Any suggestions are welcome.
I'm not sure if I understand the question, but you might consider looking into the DateTime.ToUniversalTime method, which converts the value of the DateTime object to UTC.
This way, you may be able to work with a standard time from which you can convert to any time zone you might want to use to display in your application, regardless of server location.
DateTime serverTime = DateTime.Now;
DateTime utcTime = serverTime.ToUniversalTime;
string timeZoneId = "some time zone id";
TimeZoneInfo myTime = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
DateTime label = TimeZoneInfo.ConvertTimeFromUtc(utcTime, myTime);
I am not very clear on your description. It seems as if you want your label to always show the time on the server (PC1) when the web page is loaded on the client by calling the site on the server, maybe like https://pc1. What you're doing should accomplish that: the time displayed in your label will be the system time from the server. Changing the time on the client will not affect it.
If you want your client (PC2) to show its local time, you will need to use code that runs on the client, i.e. JavaScript in most cases.
Working with dates in Javascript can be a little different from other languages/expectations, so I suggest reading the docs at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date.
Get started with var currentDate = new Date();.

Adding Removing Columns to Datagrid in Flex with States

I was developing an app that in the first state you choose a date range using dataFields then you press a button to go to another state and generate a datagrid showing an employee list and another scrollable datagrid with its columns generated dynamically having the worked hours for every employee in every date.
The step sequence to get the error message is:
You choose a date range for example: from 01/01/2013 to 01/31/2013
You press generate button (The app change the currentState = "EmployeeList" and all is OK)
You press the back button (you return to initial state and all is OK)
If you change the date range having more days than before date range then all is OK
If you change the date range having less days than before date range then next error is reached
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.controls.dataGridClasses::DataGridBase/http://www.adobe.com/2006/flex/mx/internal::columnHeaderWordWrap()
at mx.controls.dataGridClasses::DataGridItemRenderer/validateProperties()
at mx.managers::LayoutManager/validateClient()
at mx.controls.dataGridClasses::DataGridHeader/updateDisplayList()
at mx.core::UIComponent/validateDisplayList()
at mx.managers::LayoutManager/validateDisplayList()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
and if you google it then some results take to visit apache bug reporting site
https://issues.apache.org/jira/browse/FLEX-22108
And there is no more...
But I found how to solve it!
To solve it first of all I was googling a lot and i looks like no one got this error and I discover that is a Flex Bug reported to Apache. And I was analyzing the original code from DataGrid.as and DataGridColumn.as to think about a possible solution and I was making some tests and nothing work.
What I did and I hope it will be useful to someone
when you click the back button, inside the backbutton_clickEventLister() and before currentState="";
I just set columns array to new Array();
protected function bttnBack_clickEventHandler(event:Event) : void {
// This code line solved it
dtGrdWorkedHours.columns = new Array();
// Make sure of code it before state change stament
currentState = "";
}

Response.Redirect not working

I am not sure why this is not working.
I am verifying the logged on person has the correct security, if they do not I want to redirect them to another page.
If they do have the correct security the rest of the code on the page will continue to execute.
When I step through the code, it does execute the response.redirect, but the page continues to load.
strSQL = "Select * from tblSecurity Where SFID = '" & Right(My.User.Name, 4) & "' and (SecurityLevel = '900' or SecurityLevel = '850')"
ds = objData.SQLExecuteDataset(strSQL, CommandType.Text)
If ds.Tables(0).Rows.Count = 0 Then
Response.Redirect("~/NotAuthorized.aspx", False)
End If
That's exactly what you told it to do.
Passing false as the second parameter makes it not terminate the current page.
dont give the table value equal to zero...give the validation like ds.Tables(0).Rows.Count > 0... it means the table is holding the record if the given login details are right.
I tried all this and more ... and I only note my solution here for posterity and my own reference later. I ran into this problem while I had about 6 VS projects open, each in their own VS instance. Once I closed all but the one project down the problem went away. I am not sure what it was about the other project(s) that caused this particular problem but apparently VS doesn't like having too many of itself open.

RadDatePicker in RadGrid

I'm using Telerik RadGrids and I have RadDatePickers for columns with type of DateTime. However, when I want to pick a date it doesn't work at all. No errors, but it's simply not working. I've noticed that strangely I could select more days, but I want to be able to select a single day by clicking once on the given day.
I've observed that when clicking on the previous/next month I can select a day exactly as I would like, so there is a hack which might work (in my research it worked perfectly after the first postback, but before the first postback it didn't work at all):
Public Sub PageInit(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Page.ClientScript.RegisterStartupScript(GetType(TTControls.TTAjaxState),
"Page_Init_" & Me.UniqueID, "if (!(hasEndRequest)) var hasEndRequest =
false; if (!(hasEndRequest)) {var prm =
Sys.WebForms.PageRequestManager.getInstance();prm.add_endRequest(function()
{$('.rcPrev').click();console.log('clicked');});} hasEndRequest =
true;", True)
End Sub
In the code above you can see a method which will be a handler for page init.
However, I would very much like to be able to select a day by clicking on the RadDatePicker and clicking on a day. Here is how my RadDatePicker looks like:
If anybody knows the solution and decides to share it with me (if the solution is not a hack then I would be extremely happy) I would be very gladful.
Thank you in advance,
Lajos Árpád.
Will it demand a lot of work to replace your RadDateTimePicker by a RadCalendar?
The RadCalendar supports the property SelectionMode..
Have you set the SelectionMode property to Single?
Solution:
Sys.Application.add_load(function () {
$(".RadCalendar.RadCalendar_Default .rcPrev").each(function () { $(this).click(); });
});

ASP.Net links won't disable if done during postback

I'm still fairly new to ASP.Net, so forgive me if this is a stupid question.
On page load I'm displaying a progress meter after which I do a post back in order to handle the actual loading of the page. During the post back, based on certain criteria I'm disabling certain links on the page. However, the links won't disable. I noticed that if I force the links to disable the first time in (through debug) that the links disable just fine. However, I don't have the data I need at that time in order to make the decision to disable.
Code Behind
If (Not IsCallback) Then
pnlLoading.Visible = True
pnlQuote1.Visible = False
Else
pnlLoading.Visible = False
pnlQuote1.Visible = True
<Load data from DB and web service>
<Build page>
If (<Some Criteria>) Then
somelink.Disable = True
End If
End If
JavaScript
if (document.getElementById('pnlQuote1') === null) {
ob_post.post(null, 'PerformRating', ratingResult);
}
ob_post.post is an obout js function that does a normal postback and then follows up with a call to the server method named by the second param. then followed by the call to a JavaScript method named by the third param. The first parameter is the page to post back to. A value of null posts back to the current page.
The post back is working fine. All methods are called in the correct order. The code that gives me trouble is under the code behind in bold. (somelink.disabled = True does not actually disable the link) Again, if I debug and force the disabling of the link to happen the first time in, it disables. Does anyone know what I might do to get around this?
Thanks,
GRB
Your code example is using the IsCallBack check, while the question text talks about the IsPostback Check. I'd verify that you're using Page.IsPostBack in your code to turn off the links.

Resources