I have a composite drop down calendar user control that consists of a textbox and and calendar image and a validation control. I expose a property called "TextBox" on the usercontrol which returns a reference to the textbox used within the control. This is the textbox that the user enters the date into.
In the ASPX page, I have an instance of this usercontrol:
<uc1:DropDownCalendar ID="dtmDateFirstEntry" runat="server" Required="True" />
In my code behind, I want to detect when a user has tabbed off of the textbox and, using an UpdatePanel, referesh an appropriate message depending on the date that was specified.
Elsewhere in the ASPX page I have this:
<asp:UpdatePanel ID="upIntendedStay" runat="server">
<ContentTemplate>
<asp:Label ID="Label4" runat="server" Text="Update this text from server" CssClass="ErrorText"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Here's what I do in the code behind:
If Not Me.IsPostBack Then
dtmDateFirstEntry.TextBox.AutoPostBack = True
Dim trigger As New AsyncPostBackTrigger
trigger.ControlID = dtmDateFirstEntry.TextBox.ClientID
trigger.EventName = "onChange"
upIntendedStay.Triggers.Add(trigger)
End If
When the page runs and I view the source, I see something like this:
<input id="ctl00_phPageContent_dtmDateFirstEntry_txtDate" class="DefaultTextBox" name="ctl00$phPageContent$dtmDateFirstEntry$txtDate" onchange="javascript:setTimeout('__doPostBack(\'ctl00$phPageContent$dtmDateFirstEntry$txtDate\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" style="width: 112px;" type="text" value="Mar-29-2010" />
<input id="ctl00_phPageContent_dtmDateFirstEntry_imgDate" name="ctl00$phPageContent$dtmDateFirstEntry$imgDate" src="images/calendar.JPG" style="border-width: 0px;" type="image" />
When I run it, I get this error:
A control with ID 'ctl00_phPageContent_dtmDateFirstEntry_txtDate' could not be found for the trigger in UpdatePanel 'upIntendedStay'.
I didn't think that the trigger control had to be within the UpdatePanel. I thought that was the whole point of adding the trigger.
How do I refresh this update panel changes to the text in the date usercontrol. Next I will have to add other triggers to trigger the refreshing of the Update Panel from other controls scattered across the page, so clearly all of the trigger sources cannot be within the UpdatePanel.