I am using the emptydatatempla te for a gridview control. I have a detailsview control within the emptydatatempla te. In the detailsview I have a templatefield that contains an imagebutton control and a textbox control.
When the user clicks on the imagebutton I look at the text in the textbox and display a calendar control.
This displays the calendar with the month I would expect. However, I then want to change the text property of my textbox (txtIBeginDate) with the date that was selected from the calendar control.
I am doing this using the calendar's selectionchange d event using the following code.
If I step through my code in debug everything seems to get set correctly. However, when my page is redisplayed the value in my textbox is left unchanged.
Can anyone explain what I am doing wrong?
Code:
<EmptyDataTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ActivityTypeControl_ID"
DataSourceID="spListActivityTypeControlByType" DefaultMode="Insert" Height="50px"
Width="125px" BackColor="#090AAAA" OnPageIndexChanging="DetailsView1_PageIndexChanging1" BorderStyle="None" GridLines="None" OnItemCommand="DetailsView1_ItemCommand">
<Fields>
<asp:TemplateField HeaderText="Begin Date" SortExpression="BeginDate">
<InsertItemTemplate>
<asp:TextBox ID="txtIBeginDate" runat="server" Text='<%# Bind("BeginDate") %>' Width="90px"></asp:TextBox>
<asp:ImageButton ID="imgbutICalendar1" runat="server" ImageUrl="~/Images/APPTL.ICO" Height="16px"
Width="16px" OnClick="imgbutCalendar_Click" />
</InsertItemTemplate>
</asp:TemplateField>
</asp:DetailsView>
</EmptyDataTemplate>
Code:
Private ParentControl As Control
Protected Sub imgbutCalendar_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim txtDate as TextBox
ParentControl = DirectCast(sender, Control).Parent
txtDate = ParentControl.FindControl("txtIBeginDate")
Calendar.VisibleDate = CDate(txtDate.Text)
Calendar.Visible = True
End Sub
I am doing this using the calendar's selectionchange d event using the following code.
Code:
Protected Sub Calendar_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar.SelectionChanged
Calendar.Visible = False
Dim txtDate As TextBox
txtDate = ParentControl.FindControl(Session("txtIBeginDate"))
txtDate.Text = Calendar.SelectedDate.ToShortDateString
End Sub
Can anyone explain what I am doing wrong?
Comment