<p>How do I set a property of a user control in <code>ListView</code>'s <code>LayoutTemplate</code> from the code-behind?</p>

<pre><code>&lt;asp:ListView ...&gt;
&lt;LayoutTemplate&gt;
&lt;myprefix:MyControl id="myControl" ... /&gt;
&lt;/LayoutTemplate&gt;
...
&lt;/asp:ListView&gt;
</code></pre>

<p>I want to do this:</p>

<pre><code>myControl.SomeProperty = somevalue;
</code></pre>

<p>Please notice that my control is not in <code>ItemTemplate</code>, it is in <code>LayoutTemplate</code>, so it does not exist for all items, it exists only once. So I should be able to access it once, not for every data bound item.</p>

[{'answer_id': 48636, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 1, 'selected': False, 'text': '<p>Use the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.findcontrol.aspx" rel="nofollow noreferrer">FindControl</a> method on each ListViewItem.</p>\n\n<pre><code>var control = (MyControl)Item.FindControl("yourControlId");\n</code></pre>\n'}, {'answer_id': 1315742, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>To set a property of a control that is inside the LayoutTemplate, simply use the FindControl method on the ListView control.</p>\n\n<pre><code>var control = (MyControl)myListView.FindControl("myControlId");\n</code></pre>\n'}, {'answer_id': 1794556, 'author': 'tgittos', 'author_id': 218293, 'author_profile': 'https://Stackoverflow.com/users/218293', 'pm_score': 1, 'selected': False, 'text': '<p>This has been answered in this Stack Overflow question:<br />\n<a href="https://stackoverflow.com/questions/433846/access-a-control-inside-a-the-layouttemplate-of-a-listview"><a href="https://stackoverflow.com/questions/433846/access-a-control-inside-a-the-layouttemplate-of-a-listview">Access a control inside a the LayoutTemplate of a ListView</a></a></p>\n\n<p>See the comment on the accepted answer by tanathos.</p>\n\n<p>I know this was asked over a year ago, but it\'s one of the first results for the search term I used to get here, so I wanted to leave the answer for anyone else who stumbled upon it.</p>\n'}, {'answer_id': 1963712, 'author': 'Brian Mains', 'author_id': 231716, 'author_profile': 'https://Stackoverflow.com/users/231716', 'pm_score': 0, 'selected': False, 'text': '<p>The layout gets created, and fires a LayoutCreated event that says the layout has been created in the system.</p>\n\n<p>Then, you can use listview.FindControl to get a reference to that control.</p>\n'}, {'answer_id': 3926198, 'author': 'Ben Rabidou', 'author_id': 469285, 'author_profile': 'https://Stackoverflow.com/users/469285', 'pm_score': 4, 'selected': False, 'text': '<pre><code>var control = (MyControl)myListView.FindControl("myControlId");\n</code></pre>\n\n<p>This will work but make sure you do it after the data bind or the LayoutTemplate will not have been created thus throwing an error.</p>\n'}, {'answer_id': 52902606, 'author': 'Jeff', 'author_id': 3128942, 'author_profile': 'https://Stackoverflow.com/users/3128942', 'pm_score': 0, 'selected': False, 'text': '<p>In case you need the VB.net version, here it is:</p>\n\n<pre><code>Dim control = CType(myListView.FindControl("myControlId"), MyControl)\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/48616', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/31505/']