That's so simple and i don't know why i didn't think of that? here's what i did
i added a hidden field to my page
<asp:HiddenField ID="hdnDate" runat="server" />
then my dayrender i got rid of the handler and added an onclick attribute.
Code:
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)
Dim mdItem As MyDates
Dim strCellContent As New StringBuilder
Dim imgButton As New ImageButton
If MyCollection Is Nothing Then
GetSchedule()
End If
For Each mdItem In MyCollection
Dim Diff As Long = DateDiff(DateInterval.Day, e.Day.Date, Date.Today)
If Diff > 0 Then
e.Cell.ToolTip = " "
e.Day.IsSelectable = False
Else
e.Day.IsSelectable = True
e.Cell.ToolTip = "Click date to schedule appointment."
End If
If e.Day.Date = mdItem.DateSlot Then
strCellContent.Append("<br />")
strCellContent.Append("<span style='font-size:10pt; color: saddlebrown'>")
If mdItem.TakenSlots = mdItem.ScheduledSlots Then
imgButton = Nothing
strCellContent.Append("There are no more available appointments today")
Else
imgButton.ID = "lnk" & e.Day.DayNumberText
imgButton.ImageUrl = "~/Images/Reserve.jpg"
imgButton.ToolTip = "Click here to schedule an appointment."
imgButton.Attributes.Add("onclick", "document.getElementById('" & hdnDate.ClientID & "').value='" & e.Day.Date.ToShortDateString & "';")
strCellContent.Append((mdItem.ScheduledSlots - mdItem.TakenSlots).ToString & " Slots open.</span><br />")
End If
strCellContent.Append("<br />")
strCellContent.Append("</span><br />")
e.Cell.Controls.Add(New LiteralControl(strCellContent.ToString()))
If Not imgButton Is Nothing Then
e.Cell.Controls.Add(imgButton)
End If
End If
Next
End Sub
then on the page load i put an ispostback
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
GetSchedule()
Else
ShowTimeSlots(hdnDate.value)
End If
End Sub
then my sub i want to call when the button is clicked
Code:
Protected Sub ShowTimeSlots(ByVal SearchDate As String)
Dim SelectedDate As Date = CDate(SearchDate)
Dim sqlCon As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("cnsGMS").ConnectionString)
Dim sqlCmd As New System.Data.SqlClient.SqlCommand("sp_GetScheduleByDate")
Dim sqlDR As System.Data.SqlClient.SqlDataReader = Nothing
Try
sqlCon.Open()
sqlCmd.Connection = sqlCon
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
sqlCmd.Parameters.Add("@SearchDate", SqlDbType.DateTime)
sqlCmd.Parameters("@SearchDate").SqlValue = SelectedDate
sqlDR = sqlCmd.ExecuteReader
Dim strDivContent As String = ""
Do While sqlDR.Read()
strDivContent = strDivContent & "<table style='text-align:left'>"
strDivContent = strDivContent & "<tr>"
strDivContent = strDivContent & "<td>" & sqlDR("TimeSlot").ToString & "</td>"
strDivContent = strDivContent & "<td><a href='Reserve.aspx?date=" & Calendar1.SelectedDate.ToShortDateString & "&time=" & sqlDR("TimeSlot").ToString & "' target='_blank'>Reserve This Time</a>"
strDivContent = strDivContent & "</tr>"
strDivContent = strDivContent & "</table>"
Loop
If strDivContent.Length > 0 Then
daydetail_render.InnerHtml = strDivContent
Else
daydetail_render.InnerHtml = "<h3 style='color:red'>There Are No Appointments Available On This Day</h3>"
End If
daydetail.Visible = True
Finally
sqlCon.Close()
sqlDR.Close()
sqlCmd = Nothing
sqlDR.Close()
sqlCon = Nothing
End Try
selectedday.InnerHtml = SelectedDate.ToShortDateString
GetSchedule()
End Sub