删除所有子控件我有下一个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();
但它不工作,我得到的消息:
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
有什么不对?我应该如何正确地做到这一点?
您是否尝试过使用Panel2来确保通话正常?如果这个调用起作用,那么我认为它的意思是它不仅杀死了子控件,而且还杀死了主控件(本身)。但是,我不认为这样做,但我可能是错的。 – XstreamINsanity 2010-08-19 12:51:55
是的,其他面板(panel2,panel3)删除所有的孩子(但不是自己)。这很好。 但Panel1不想删除子控件(即使它包含在其他面板或它有邻居面板,所以内容不为空) – 2010-08-19 13:09:59
我认为问题出在子控件中。 – 2010-08-19 13:10:59