calendar SelectionChanged

G

Guest

I have a basic calendar and a SelectionChanged event (asp.net 2.0).

How can I handle it when a user chooses the same date again, in this case
the SelectionChanged event is not fired because, well, the date selected
hasnt changed.

Is there a calendar.clearSelection type method on the calendar I can use?
 
M

Mark Rae

I have a basic calendar and a SelectionChanged event (asp.net 2.0).

How can I handle it when a user chooses the same date again, in this case
the SelectionChanged event is not fired because, well, the date selected
hasnt changed.

That's absolutely right...
Is there a calendar.clearSelection type method on the calendar I can use?

What are you trying to do...? What do you want to happen if the user clicks
the calendar but the selection hasn't changed...?
 
G

Guest

All I am doing is placing the selected date into a textbox. It is a data
entry screen so sometimes the selected date will be the same as the last one.

Any way of handling this? I thought this would be a common problem.
 
M

Mark Rae

All I am doing is placing the selected date into a textbox. It is a data
entry screen so sometimes the selected date will be the same as the last
one.

Any way of handling this? I thought this would be a common problem.

I'm clearly not grasping the problem here...

You have a textbox and, presumably, a button or something which pops the
calendar, right...?

The user clicks a date, and the textbox is updated, right...?

At this point, don't you close the calendar...?
 
G

Guest

yes correct, I might be in the wrong forum. I should have added that I am
using ms ajax 1.0 and the calendar closes down fine. I kinda assumed this was
the same behaviour for non ajax apps.

So this works fine after the page postbacks?
 
M

Mark Rae

yes correct, I might be in the wrong forum. I should have added that I am
using ms ajax 1.0 and the calendar closes down fine. I kinda assumed this
was
the same behaviour for non ajax apps.

So this works fine after the page postbacks?

Apologies again - am still not grasping the problem...

If the calendar closes when the user selects a date, then how are they able
to click the date again...?
 
G

Guest

Sorry for the confusion.

Step 1:
User selects a date from the pop up and the date is put into a textbox using
the selectionChange event of the calendar. Calendar closes.

Step 2:
Do the same thing again and choose the same date you chose in first step.
The selectionChange event does not fire (as expected). So how can I clear the
selection or make the event fire.
 
M

Mark Rae

Sorry for the confusion.

Step 1:
User selects a date from the pop up and the date is put into a textbox
using
the selectionChange event of the calendar. Calendar closes.

Step 2:
Do the same thing again and choose the same date you chose in first step.
The selectionChange event does not fire (as expected). So how can I clear
the
selection or make the event fire.

Ah... Please post your code...
 
G

Guest

here is a very simple example of the issue.



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>

Code behind:

Partial Class test
Inherits System.Web.UI.Page

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar1.SelectionChanged
TextBox1.Text = Calendar1.SelectedDate
End Sub
End Class
 
M

Mark Rae

here is a very simple example of the issue.

But I don't think that's the problem... Do you not have more code than this
e.g. a DayRender method which disables the SelectedDate or something when
the Calendar is opened...?
 
D

David Wier

One option here, though I know it may not be what you're looking for, is to
have a button to set the date in the textbox, using the selected date in the
calendar
Other than that - when the calendar pops up, you could set the selected date
of the calendar to an alternate date....then, the selectionchanged event
would fire via their selection...

(just throwing out ideas here)
 
M

Mark Rae

Other than that - when the calendar pops up, you could set the selected
date
of the calendar to an alternate date....then, the selectionchanged event
would fire via their selection...

I usually don't do that - instead, I use the VisibleDate property to make
sure the Calendar displays the correct month, and then the DayRender event
to highlight the "associated" date in some way e.g. setting the BackColor to
Grey or something...

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.visibledate(VS.80).aspx
 
G

Guest

There is other code on the page, but its not related to the issue.

So I think you understand the issue? Do you know how to disable the
previously selected date when using the calendar on subsequent times.

You mentioned you disable the selected date in the dayRender method, what is
the code for that?
 
M

Mark Rae

Please stop top-posting - it is very irritating...
There is other code on the page, but its not related to the issue.

Are you sure...?
So I think you understand the issue? Do you know how to disable the
previously selected date when using the calendar on subsequent times.

When you open a calendar, it doesn't have a selected date until you set its
SelectedDate property.

Create a completely new aspx page and put the following markup in it:

<asp:Calendar ID="calTest" runat="server" />

Now open the page and click the same date over and over again - no problem,
right...?

You say that you are able to click a date the first time the calendar is
opened but, when you open it a second time, you are unable to click the same
date.

This won't happen by itself - you must be doing it...

You say that the calendar is associated with a text box - how is it
associated with a text box...?
 
G

Guest

Top posting? What?

Anyways, so on the new page you created below you have added a calendar.
Thats fine. Now add a text box to the same page. Now add a
calendar.SelectionChange, something like this...

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar1.SelectionChanged
TextBox1.Text = Calendar1.SelectedDate
End Sub
End Class

So choose a date from the calendar and the date goes into the textbox as a
result of the code above. Now clear out the textbox and choose the same date
again from the calendar. As the selected date has not changed the
calendar.selectionChanged event doesnt not fire as expected.

So how can you remove the previous selected date or make the
selectionChanege veent fire. Do you see the problem?
 
M

Mark Rae

Top posting? What?

Top posting... Placing your reply *above* the post you're replying to
instead of *below* it... Generally considered bad netiquette...


A - Because it interrupts the normal way of reading conversations i.e. from
start to finish

Q - Why is top posting irritating...?

So how can you remove the previous selected date

Calendar1.SelectedDate = Nothing
 
G

Guest

Thats not correct, I was replying to your earlier post. You had replied to
somebody else i.e. David.

Which event have you put the Calendar1.SelectedDate = Nothing into ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top