Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用母版页清除表单上的所有字段_C#_Asp.net_.net - Fatal编程技术网

C# 使用母版页清除表单上的所有字段

C# 使用母版页清除表单上的所有字段,c#,asp.net,.net,C#,Asp.net,.net,我正在尝试通过单击按钮清除表单,我现在的位置如下: ContentPlaceHolder mpContentPlaceHolder; mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"); foreach (Control ctrl in mpContentPlaceHolder.Controls) {

我正在尝试通过单击按钮清除表单,我现在的位置如下:

     ContentPlaceHolder mpContentPlaceHolder;
        mpContentPlaceHolder =
   (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");

        foreach (Control ctrl in mpContentPlaceHolder.Controls)
        {
            lblMessageX.Text = ctrl.ToString();
            if (ctrl is TextBox)
                ((TextBox)ctrl).Text = string.Empty;
            else if (ctrl is DropDownList)
                ((DropDownList)ctrl).ClearSelection();
        }
它只循环一次,并找到:System.Web.UI.LiteralControl

它不是在正确的地方搜索吗

我的模型看起来像:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <asp:Accordion   
    ID="Accordion1"   
    CssClass="accordion"  
    HeaderCssClass="accordionHeader"  
    HeaderSelectedCssClass="accordionHeaderSelected"  
    ContentCssClass="accordionContent"   
    runat="server">  

<Panes >
<asp:AccordionPane runat="server" >
    <asp:DropDownList ID="ddlOrg" runat="server"  AutoPostBack="true" CssClass="myinputstyle"
                   OnSelectedIndexChanged="ddlOrg_SelectedIndexChanged" />  
      <asp:TextBox ID="txtCase" runat="server" CssClass="myinputstyleS" MaxLength="8" />  
//and so on and so forth

//等等等等

您需要执行递归搜索以获取页面上的所有控件,因为并非所有控件都位于ContentPlaceHolder下方。相反,它包含一些本身包含其他控件的控件

Content Place Holder
-->LiteralControl
   -->Other Control 1
   -->Other Control 2
   -->Other Control 3
      -->Maybe another level 1
      -->Maybe another level 2
   -->Other Control 4
控件将返回“其他控件1”到4,但不返回“可能是另一个级别1”或“可能是另一个级别2”。要获得这些,您需要调用“其他控件3”。控件


查看调试器以查看确切的层次结构。

您需要执行递归搜索以获取页面上的所有控件,因为并非所有控件都位于ContentPlaceHolder下方。相反,它包含一些本身包含其他控件的控件

Content Place Holder
-->LiteralControl
   -->Other Control 1
   -->Other Control 2
   -->Other Control 3
      -->Maybe another level 1
      -->Maybe another level 2
   -->Other Control 4
控件将返回“其他控件1”到4,但不返回“可能是另一个级别1”或“可能是另一个级别2”。要获得这些,您需要调用“其他控件3”。控件


查看调试器以查看确切的层次结构。

在生命周期中何时调用此功能?您的意思是什么?当我点击按钮时…在生命周期中什么时候调用它?你是什么意思?当我点击按钮。。。