This is a migrated thread and some comments may be shown as answers.

Unexpected behaviour using AutoPostBack

3 Answers 86 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
iTools
Top achievements
Rank 1
iTools asked on 28 Jul 2009, 03:43 AM
I want to have a calendar where a date selection causes a user to be redirected to an appropriate page. So, I set AutoPostBack="true" for the RadCalendar control and handle the SelectionChanged event on the server-side. Although, if user navigates from the page back to the calendar and hover the mouse over the previously selected date it appears selected.

How to replicate...

Markup:
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
    <meta http-equiv="expires" content="-1" /> 
    <meta http-equiv="Pragma" content="no-cache" /> 
</head> 
<body> 
    <form runat="server"
    <asp:ScriptManager runat="server" /> 
    <telerik:RadCalendar ID="RadCalendar1" runat="server" AutoPostBack="true" /> 
    </form> 
</body> 
</html> 

Codebehind:
    Private Sub RadCalendar1_SelectionChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) Handles RadCalendar1.SelectionChanged 
        Dim d As String = e.SelectedDates(0).Date.ToShortDateString() 
        RadCalendar1.SelectedDates.Clear() 
        Response.Redirect("WebForm1.aspx?date=" + d) 
    End Sub 

 When the user presses the browser back button I want the calendar to be "fresh" and not have the hidden selection.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Jul 2009, 07:55 AM
Hi Jan,

Try attaching OnLoad client event to RadCalendar to deselect the dates when clicking the back button in browser. Give a try with this and see whether it helps.

VB:
 
Protected Sub RadCalendar1_SelectionChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) 
    If e.SelectedDates.Count <> 0 Then 
        Dim d As String = e.SelectedDates(0).[Date].ToShortDateString() 
        Response.Redirect("WebForm1.aspx?date=" & d) 
    End If 
End Sub 

JavaScript:
 
<script type="text/javascript"
function OnLoad(sender, args) 
    var dates = sender.get_selectedDates(); 
    if(sender.get_selectedDates().length != 0) 
    { 
        sender.unselectDates(dates); 
    } 
</script> 

Shinu
0
iTools
Top achievements
Rank 1
answered on 28 Jul 2009, 07:59 PM
Hi Shinu,

The suggested idea you provided causes a SelectionChanged event to be raised (where the SelectedDates collection is empty) on the back button being pressed which is undesired. Is there a workaround to this?

Thanks.
0
Martin
Telerik team
answered on 31 Jul 2009, 12:40 PM
Hello Jan,

You can just add a check to the SelectionChanged event handler to verify that the SelectedDates collection has any members like this:

Protected Sub RadCalendar1_SelectionChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) 
     If e.SelectedDates.Count > 0 Then 
         Dim d As String = e.SelectedDates(0).Date.ToShortDateString() 
         RadCalendar1.SelectedDates.Clear() 
         Response.Redirect("WebForm1.aspx?date=" + d) 
     End If 
End Sub 


Best regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
iTools
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
iTools
Top achievements
Rank 1
Martin
Telerik team
Share this question
or