更新面板的错误:控制与ID" XXX"不能在UpdatePanel中发现 [英] Update Panel error: Control with the ID "xxx" could not be found in the UpdatePanel

查看:136
本文介绍了更新面板的错误:控制与ID" XXX"不能在UpdatePanel中发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复合下拉日历用户控件,由一个文本框,和日历形象和验证控制。我揭露了一个名为文本框上,它返回一个引用控制范围内使用文本框的用户控件属性。这是用户输入的日期到文本框中。

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.

在ASPX页面,我有这样的用户控件的一个实例:

In the ASPX page, I have an instance of this usercontrol:

   <uc1:DropDownCalendar ID="dtmDateFirstEntry" runat="server"  Required="True" />

在我的$ C $落后C,我想检测当用户关闭标签的文本框,并使用一个UpdatePanel,referesh适当的信息取决于所指定的日期。

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.

在其他地方ASPX页面我有这样的:

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>

下面是我做的背后,code:

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" />&nbsp;

当我运行它,我得到这个错误:

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'. 

我没有想到的是触发控制必须是在UpdatePanel内。我认为这是增加触发的整点。

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.

我如何刷新此更新面板改变在日期用户控件的文本。接下来,我将不得不增加其他触发器触发从分散在页面的其他控件的更新面板的清爽,所以就明确了所有的触发源不能在UpdatePanel内。

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.

要尽量的简化情况,我添加了一个测试文本框,TextBox1中的更新面板:

To try an simplify the situation, I added a test Textbox, textbox1 to the update panel:

 <asp:UpdatePanel ID="upIntendedStay" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Label ID="Label4" runat="server" Text="Update tHis text from server" CssClass="ErrorText"></asp:Label>
    </ContentTemplate>
    </asp:UpdatePanel>

然后我得到了错误:

I then get the error:

无法找到名为某一事件的onchange对相关控制TextBox1的在UpdatePanel的'upIntendedStay触发。

Could not find an event named 'onchange' on associated control 'TextBox1' for the trigger in UpdatePanel 'upIntendedStay'.

OK,我添加了一个文本框,TextBox1的,在UpdatePanel内,变客户端Id为ID和的OnChange到框TextChanged和它的作品。但我仍然得到同样的错误,如果文本框是不是在UpdatePanel内。

OK, I added a textbox, TEXTBOX1, within the UpdatePanel, change "ClientId" to "ID" and "OnChange" to "TextChanged" and it works. But I still get the same error if the textbox is not within the UpdatePanel.

必须触发文本框是更新面板内?这是一个沉重的要求。

Must the triggering textbox be within the update panel? This is a crippling requirement.

Dim trigger As New AsyncPostBackTrigger
'trigger.ControlID = dtmDateFirstEntry.TextBox.ID '<<<<<<<<<<<<<<<<<<<<<
trigger.ControlID = TextBox1.ID
trigger.EventName = "TextChanged"
upIntendedStay.Triggers.Add(trigger)

OK..When我谨athe日历用户控件放入更新面板,我得到这个错误:

OK..When I move athe calendar usercontrol into the Update panel, I get this error:

ID为txtDate控制找不到在UpdatePanel的'upIntendedStay触发。

A control with ID 'txtDate' could not be found for the trigger in UpdatePanel 'upIntendedStay'.

嗯。它似乎有一个问题找到嵌入式控制,即使它的更新面板内,但它没有问题,发现未嵌入一个用户控件!

Hmmm. It's apparently having an issue finding the embedded control even though it's within the update panel, but it has no problem finding a plain textbox that is not embedded within a usercontrol!!

推荐答案

据我所理解的文本框嵌入到用户控制dt​​mDateFirstEntry。你不能直接使用包含由用户控制的控制。如果你想使用它们作为触发器的用户控件必须公开自己的子控件的事件。

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将通过dtmDateFirstEntry暴露的事件。你知道如何做到这一点?

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

这篇关于更新面板的错误:控制与ID&QUOT; XXX&QUOT;不能在UpdatePanel中发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆