snipt

Ctrl+h for KB shortcuts
#17733

C#

findcontrol

1
2
3
4
5
            var div = new HtmlGenericControl("div");
            div.Controls.Add(new Literal() { ID = "litSomeLit", Text = "blah" });
            var lit = (Literal)div.FindControl("litSomeLit");
            Assert.IsTrue(div.Controls[0] is Literal);
            Assert.IsNotNull(lit);
https://snipt.net/embed/89e95f95593a761442ac7236f54519bb/
https://snipt.net/raw/89e95f95593a761442ac7236f54519bb/
89e95f95593a761442ac7236f54519bb
csharp
C#
5
2014-04-16T21:15:58
True
False
/api/public/snipt/17733/
findcontrol
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a> <span class="kt">var</span> <span class="n">div</span> <span class="p">=</span> <span class="k">new</span> <span class="n">HtmlGenericControl</span><span class="p">(</span><span class="s">&quot;div&quot;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">div</span><span class="p">.</span><span class="n">Controls</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">Literal</span><span class="p">()</span> <span class="p">{</span> <span class="n">ID</span> <span class="p">=</span> <span class="s">&quot;litSomeLit&quot;</span><span class="p">,</span> <span class="n">Text</span> <span class="p">=</span> <span class="s">&quot;blah&quot;</span> <span class="p">});</span> </span><span id="L-3"><a name="L-3"></a> <span class="kt">var</span> <span class="n">lit</span> <span class="p">=</span> <span class="p">(</span><span class="n">Literal</span><span class="p">)</span><span class="n">div</span><span class="p">.</span><span class="n">FindControl</span><span class="p">(</span><span class="s">&quot;litSomeLit&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">Assert</span><span class="p">.</span><span class="n">IsTrue</span><span class="p">(</span><span class="n">div</span><span class="p">.</span><span class="n">Controls</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="k">is</span> <span class="n">Literal</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">Assert</span><span class="p">.</span><span class="n">IsNotNull</span><span class="p">(</span><span class="n">lit</span><span class="p">);</span> </span></pre></div> </td></tr></table>
csharp