我想清空面板中的文本框控件。 請解釋。如何清除面板中的文本框控件
下面是我的代碼:
<asp:Panel ID="Panel_CreateLead" runat="server" Visible="false" BackColor="#eff2f6" Width="98%">
<asp:Literal ID="LiteralNoLead" runat="server" Text="<span style='color:red'>No Lead Exists. Please fill the Lead Template to Create New Lead.</span>"></asp:Literal>
<asp:Table ID="Table_CreateLead" runat="server" Width="98%" CellSpacing="1" CellPadding="1"
Font-Names="Tahoma" BorderColor="#eff2f6" BorderStyle="Dashed">
<asp:TableHeaderRow HorizontalAlign="Center">
<asp:TableHeaderCell Text="Lead Template" Font-Bold="true" ColumnSpan="4" Font-Size="Large" />
</asp:TableHeaderRow>
<asp:TableRow ID="TableRow11" runat="server">
<asp:TableCell Text="General" Font-Bold="true" ForeColor="Blue"></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell Text="Topic">
<asp:Literal ID="Literal_Topic" Text="<span style='color:red'>*</span>" runat="server" />
</asp:TableCell>
<asp:TableCell ColumnSpan="3">
<asp:TextBox ID="TextBox_leadname" Width="80%" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator_TextBox_leadname" runat="server" ControlToValidate="TextBox_leadname" ValidationGroup="LeadVaidation" ErrorMessage="Enter Topic" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow23" runat="server">
<asp:TableCell Text="Currency" ></asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="DropDownList_Currency" runat="server">
</asp:DropDownList>
</asp:TableCell>
<asp:TableCell Text="No. of Employees" ></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBox_Employees" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Button ID="Button_lead" runat="server" Text="Submit" OnClick="create_lead" ValidationGroup="LeadVaidation"/>
</asp:TableCell>
<asp:TableCell>
<asp:Literal ID="Literal_lead" runat="server"></asp:Literal>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
我已經使用的方法明文(Panel_CreateLead);在頁面加載不起作用。
以明文的形式使用()的代碼:
private void clearText(Panel PanelID)
{
foreach (Control c in PanelID.Controls)
{
if (c is TextBox)
{
TextBox questionTextBox = c as TextBox;
if (questionTextBox != null)
{
questionTextBox.Text = "";
}
}
}
}
所有這些都不能正常工作。請幫忙。
嘗試PreRender事件而不是Page_Load .... – 2GDev 2011-05-30 13:45:58
請參見http:// st ackoverflow.com/questions/4863051/loop-through-textboxes – abatishchev 2011-05-30 14:11:47