从父控件中删除所有子控件时出错
我有下一个 aspx 页面:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="newsEditor.aspx.cs" Inherits="ExpertSiteV2.newsEditor" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Assembly="ExpertSiteV2" Namespace="ExpertSiteV2" TagPrefix="custom" %>
<asp:Content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:Panel ID="Panel2" runat="server" Width="660" Style="margin-bottom: 10px;">
<asp:Label ID="Label1" runat="server" Text="Label" Width="150">Заголовок новости</asp:Label>
<asp:TextBox ID="newsTitle" runat="server" Width="500" Style="float: right;"></asp:TextBox>
</asp:Panel>
<custom:CustomEditor ID="Editor3" runat="server" Height="300" Width="660" BackColor="White" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Panel ID="Panel3" runat="server" Style="margin-top: 5px;" CssClass="buttonPanel">
<asp:ImageButton ID="SaveImageButton1" runat="server" ImageUrl="img/save_32.png"
ToolTip="Сохранить новость" />
<asp:LinkButton ID="SaveLinkButton1" runat="server" ToolTip="Сохранить новость">Сохранить</asp:LinkButton>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" ImageUrl="img/block_32.png"
PostBackUrl="news.aspx" ToolTip="Вернуться к странице новостей" />
<asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Вернуться к странице новостей"
CausesValidation="False" PostBackUrl="news.aspx">Отмена</asp:LinkButton>
</asp:Panel>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Заголовок должен быть заполнен!"
ControlToValidate="newsTitle" Display="Dynamic">
</asp:RequiredFieldValidator>
</asp:Panel>
</asp:Content>
我想删除 Panel1
的所有内容。我编写了代码:
Panel1.Controls.Clear();
但它不起作用,我收到消息:
页面不能为空。请确保 正在执行此操作 在 ASP.NET 请求的上下文中。 描述:未处理的异常 执行期间发生的 当前的网络请求。请查看 堆栈跟踪以获取有关的更多信息 错误及其起源 代码。
异常详细信息: System.InvalidOperationException:页面 不能为空。请确保 该操作正在执行 ASP.NET 请求的上下文。
来源错误:
生成了未处理的异常 当前执行期间 网络请求。有关信息 异常的起源和地点 可以使用异常来识别 下面的堆栈跟踪。
堆栈跟踪:
[InvalidOperationException:页面 不能为空。请确保 该操作正在执行 ASP.NET 请求的上下文。]
System.Web.UI.ScriptManager.get_IPage() +373832 System.Web.UI.ScriptManager.OnPagePreRenderComplete(对象 发送者,EventArgs e) +54
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8698462
System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔值 includeStagesAfterAsyncPoint)+1029块引用
有什么问题吗?我应该怎样做才正确呢?
I have the next aspx page:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="newsEditor.aspx.cs" Inherits="ExpertSiteV2.newsEditor" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Assembly="ExpertSiteV2" Namespace="ExpertSiteV2" TagPrefix="custom" %>
<asp:Content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:Panel ID="Panel2" runat="server" Width="660" Style="margin-bottom: 10px;">
<asp:Label ID="Label1" runat="server" Text="Label" Width="150">Заголовок новости</asp:Label>
<asp:TextBox ID="newsTitle" runat="server" Width="500" Style="float: right;"></asp:TextBox>
</asp:Panel>
<custom:CustomEditor ID="Editor3" runat="server" Height="300" Width="660" BackColor="White" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Panel ID="Panel3" runat="server" Style="margin-top: 5px;" CssClass="buttonPanel">
<asp:ImageButton ID="SaveImageButton1" runat="server" ImageUrl="img/save_32.png"
ToolTip="Сохранить новость" />
<asp:LinkButton ID="SaveLinkButton1" runat="server" ToolTip="Сохранить новость">Сохранить</asp:LinkButton>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" ImageUrl="img/block_32.png"
PostBackUrl="news.aspx" ToolTip="Вернуться к странице новостей" />
<asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Вернуться к странице новостей"
CausesValidation="False" PostBackUrl="news.aspx">Отмена</asp:LinkButton>
</asp:Panel>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Заголовок должен быть заполнен!"
ControlToValidate="newsTitle" Display="Dynamic">
</asp:RequiredFieldValidator>
</asp:Panel>
</asp:Content>
I want to delete all the contents of Panel1
. I write the code:
Panel1.Controls.Clear();
But it doesn't work and I get the message:
Page cannot be null. Please ensure
that this operation is being performed
in the context of an ASP.NET request.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.Exception Details:
System.InvalidOperationException: Page
cannot be null. Please ensure that
this operation is being performed in
the context of an ASP.NET request.Source Error:
An unhandled exception was generated
during the execution of the current
web request. Information regarding the
origin and location of the exception
can be identified using the exception
stack trace below.Stack Trace:
[InvalidOperationException: Page
cannot be null. Please ensure that
this operation is being performed in
the context of an ASP.NET request.]
System.Web.UI.ScriptManager.get_IPage()
+373832 System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object
sender, EventArgs e) +54
System.Web.UI.Page.OnPreRenderComplete(EventArgs
e) +8698462
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +1029Blockquote
What's wrong? How should I do it properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我写了这样的内容:
这是另一个包含所有内容的面板。我已经写道:
效果很好。
我仍然不知道为什么 Panel1 不想删除子控件。如果有人知道就写下答案。
Okay, i've written something like this:
Here is one more panel that contains everything. And I've written:
It works fine.
I still don't know why the Panel1 doesn't want to remove child controls. If someone knows just write the answer.
不能直接隐藏面板吗? Panel1.Visible = false。为什么你想删除控件。
啊哈,好吧,我现在明白了问题:
查看此项目,http://www.codeproject.com/KB/user -controls/DynamicUC.aspx
Can't you not just hide the panel? Panel1.Visible = false. why do you wanna remove the controls.
Aha ok I get the question now:
Check out this project, http://www.codeproject.com/KB/user-controls/DynamicUC.aspx