Reference an ASP control inside a function or class method
<p>How do you reference an asp.net control on your page inside a function or a class. </p>

<pre><code>private void PageLoad(object sender, EventArgs e)
{
   //An example control from my page is txtUserName
   ChangeText(ref txtUserName, "Hello World");
} 

private void ChangeText(ref HtmlGenericControl control, string text)
{
   control.InnerText = text;
}
</code></pre>

<p>Will this actually change the text of the txtUserName control?</p>

<p>I tried this and is working</p>

<pre><code>private void PageLoad(object sender, EventArgs e)
{
   ChangeText(txtUserName, "Hello World");
} 

private void ChangeText(TextBox control, string text)
{
   control.Text = text;
}
</code></pre>
