gpt4 book ai didi

c# - ID为 'UpdatePanel1'的UpdatePanel的Controls属性不能直接修改

转载 作者:行者123 更新时间:2023-11-30 13:48:41 25 4
gpt4 key购买 nike

popup pn = new popup();
pn.Title = "New Message";
pn.Message = "New Study Received";
pn.ColorStyle = popupColorStyle.Green;
UpdatePanel1.Controls.Add(pn);

popup 是我的自定义控件,它显示一个弹出窗口,UpdatePanel1 是一个 ajax 控件。我想在不重新加载整个页面的情况下显示弹出窗口。最后一行向我抛出一个错误,因为“无法直接修改 ID 为‘UpdatePanel1’的 UpdatePanel 的控件属性。要更改 UpdatePanel 的内容,请修改 ContentTemplateContainer 属性的子控件。”我正在使用 ASP.NET 3.5 ...谁能知道这个问题

最佳答案

错误消息会准确地告诉您哪里出了问题以及如何解决。您需要将控件添加到 ContentTemplateContainer.Controls,而不是将控件添加到 Controls,即

UpdatePanel1.ContentTemplateContainer.Controls.Add(pn);

来自MSDN documentation:

The ContentTemplateContainer property enables you to programmatically add child controls to the UpdatePanel control without having to define a custom template that inherits from the ITemplate interface.

关于c# - ID为 'UpdatePanel1'的UpdatePanel的Controls属性不能直接修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11818786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com