Update Panel error: Control with the ID “xxx” could not be found in the UpdatePanel

后端 未结 5 1855
小蘑菇
小蘑菇 2021-01-13 12:05

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

相关标签:
5条回答
  • 2021-01-13 12:27

    Add The Trigger Before Page_Load, ex. Page_Init.

    0 讨论(0)
  • 2021-01-13 12:36

    You may want to try:

    ...
    trigger.ControlID = dtmDateFirstEntry.TextBox.ID
    trigger.EventName = "TextChanged"
    ...
    

    that is, use the ID instead of the ClientID for the ControlID and do not use the "On" prefix for the EventName.

    0 讨论(0)
  • 2021-01-13 12:38

    For an html control runat server inside of an update panel you need to dereference the update panel to get a handle to the control on the server side:

    using System.Web.UI.HtmlControls;

    HtmlControl x = (HtmlControl)this.MyUpdatePanel.FindControl("MyHtmlControl");
    
    0 讨论(0)
  • 2021-01-13 12:46

    ASPX Page:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:UpdatePanel ID="upIntendedStay" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                 <uc1:DropDownCalendar ID="DropDownCalendar1" runat="server" />
                <asp:Label ID="Label4" runat="server" Text="Update tHis text from server" CssClass="ErrorText"></asp:Label>
    
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>
    

    Code behind:

    If Not Page.IsPostBack Then
    
        Dim trigger As New AsyncPostBackTrigger
        TextBox3.AutoPostBack = True
        trigger.ControlID = TextBox3.ID
        trigger.EventName = ""
        upIntendedStay.Triggers.Add(trigger)
    
        Dim trigger2 As New AsyncPostBackTrigger
        DropDownCalendar1.TextBox.AutoPostBack = True
        trigger2.ControlID = DropDownCalendar1.ID
        trigger2.EventName = "DateChanged"
        upIntendedStay.Triggers.Add(trigger2)
    
    End If
    
    Label4.Text = Now.ToString
    

    And add this event to your user control:

    Public Event DateChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    ..and viola!

    0 讨论(0)
  • 2021-01-13 12:47

    According what I understand the textbox is embedded on User Control dtmDateFirstEntry. You CANNOT use directly a control contained by a user control. The user control MUST expose the events of his child controls if you want to use them as triggers.

    <asp:UpdatePanel ID="upIntendedStay" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="dtmDateFirstEntry" EventName="DateChanged" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label4" runat="server" Text="Update tHis text from server" CssClass="ErrorText"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>

    DateChanged would be an event exposed by dtmDateFirstEntry. Do you know how to do this?

    0 讨论(0)
提交回复
热议问题