在代码隐藏处设置 updatepanelanimationextender TargetControId
在用户控件内部,我有 updatepanelanimationextender,当我将此控件添加到网页时,我想将 updatepanel 的 Id 作为参数传递给控件的属性。
Usercontrol:
public partial class Controls_UpdateProgress : System.Web.UI.UserControl
{
public string UpdatePanelID { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UpdatePanelAnimationExtender1.TargetControlID = UpdatePanelID;
}
}
}
<cc1:updatepanelanimationextender id="UpdatePanelAnimationExtender1" runat="server" >
<Animations>
<OnUpdating>
<Parallel duration="0" >
<ScriptAction Script="onUpdating();" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel duration="0">
<ScriptAction Script="onUpdated();" />
</Parallel>
</OnUpdated>
</Animations>
</cc1:updatepanelanimationextender>
WebPage: UpdatePanel1 是 updatepanel 的 id。
<uc1:UpdateProgress ID="UpdateProgress1" runat="server" UpdatePanelID="UpdatePanel1" />
我收到错误:
目标控件ID “UpdatePanelAnimationExtender1”不是 有效的。该值不能为空或 空。
Inside usercontrol I have updatepanelanimationextender, when I add this control to a webpage I want to pass updatepanel's Id as parameter to control's property.
Usercontrol:
public partial class Controls_UpdateProgress : System.Web.UI.UserControl
{
public string UpdatePanelID { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UpdatePanelAnimationExtender1.TargetControlID = UpdatePanelID;
}
}
}
<cc1:updatepanelanimationextender id="UpdatePanelAnimationExtender1" runat="server" >
<Animations>
<OnUpdating>
<Parallel duration="0" >
<ScriptAction Script="onUpdating();" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel duration="0">
<ScriptAction Script="onUpdated();" />
</Parallel>
</OnUpdated>
</Animations>
</cc1:updatepanelanimationextender>
WebPage: UpdatePanel1 is an id of the updatepanel.
<uc1:UpdateProgress ID="UpdateProgress1" runat="server" UpdatePanelID="UpdatePanel1" />
I get error:
The TargetControlID of
'UpdatePanelAnimationExtender1' is not
valid. The value cannot be null or
empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AJAX 控件扩展程序不会将其
TargetControlID
存储在ViewState
中(我使用 Reflector 在System.Web.Extensions
3.5 中签入,该属性仅获取/设置私人成员)。因此,您存储的值在回发时会丢失。您必须在每个请求中存储该值:
The AJAX control extenders do not store their
TargetControlID
in theViewState
(I checked inSystem.Web.Extensions
3.5 with Reflector and that property only gets/sets a private member). Thus, the value you stored is lost on postback.You'll have to store the value in every request:
为了避免该异常,您应该首先确保 UpdatePanelID 不为 null...
如果您希望以编程方式从父页面设置 UpdatePanelID 的属性,则需要将 UpdateProgress1 转换为 Controls_UpdateProgress 实例。为此,请执行以下操作...
To avoid that exception, you should first make sure that UpdatePanelID is not null...
If you desire to set the property of the UpdatePanelID from the parent page programmatically you will need to cast UpdateProgress1 as a Controls_UpdateProgress instance. To do that, do something like this...