Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Below are methods I use to clear text from a <strong>type</strong> of control that implements ITextBox.</p> <p>I noticed in the example default boolean values are set. I'm sure you can modify it to set default values of boolean components.</p> <p>Pass the Clear method a control type (TextBox, Label... etc) and a control collection, and it will clear all text from controls that implement ITextBox.</p> <p>Something like this:</p> <pre><code>//Clears the textboxes WebControlUtilities.ClearControls&lt;TextBox&gt;(myPanel.Controls); </code></pre> <p>The Clear method is meant for a Page or Masterpage. The control collection type may vary. ie. Form, ContentPlaceHolder.. etc</p> <pre><code> /// &lt;summary&gt; /// Clears Text from Controls...ie TextBox, Label, anything that implements ITextBox /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;Collection Type, ie. ContentPlaceHolder..&lt;/typeparam&gt; /// &lt;typeparam name="C"&gt;ie TextBox, Label, anything that implements ITextBox&lt;/typeparam&gt; /// &lt;param name="controls"&gt;&lt;/param&gt; public static void Clear&lt;T, C&gt;(ControlCollection controls) where C : ITextControl where T : Control { IEnumerable&lt;T&gt; placeHolders = controls.OfType&lt;T&gt;(); List&lt;T&gt; holders = placeHolders.ToList(); foreach (T holder in holders) { IEnumerable&lt;C&gt; enumBoxes = holder.Controls.OfType&lt;C&gt;(); List&lt;C&gt; boxes = enumBoxes.ToList(); foreach (C box in boxes) { box.Text = string.Empty; } } } /// &lt;summary&gt; /// Clears the text from control. /// &lt;/summary&gt; /// &lt;typeparam name="C"&gt;&lt;/typeparam&gt; /// &lt;param name="controls"&gt;The controls.&lt;/param&gt; public static void ClearControls&lt;C&gt;(ControlCollection controls) where C : ITextControl { IEnumerable&lt;C&gt; enumBoxes = controls.OfType&lt;C&gt;(); List&lt;C&gt; boxes = enumBoxes.ToList(); foreach (C box in boxes) { box.Text = string.Empty; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload