<p>How do I assign a method's output to a textbox value without code behind?</p>

<pre><code>&lt;%@ Page Language="VB" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;script runat="server"&gt;
    Public TextFromString As String = "test text test text"
    Public TextFromMethod As String = RepeatChar("S", 50) 'SubSonic.Sugar.Web.GenerateLoremIpsum(400, "w")

    Public Function RepeatChar(ByVal Input As String, ByVal Count As Integer)
        Return New String(Input, Count)
    End Function
&lt;/script&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head id="Head1" runat="server"&gt;
    &lt;title&gt;Test Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;%=TextFromString%&gt;
        &lt;br /&gt;
        &lt;asp:TextBox ID="TextBox1" runat="server" Text="&lt;%# TextFromString %&gt;"&gt;&lt;/asp:TextBox&gt;
        &lt;br /&gt;
        &lt;%=TextFromMethod%&gt;
        &lt;br /&gt;
        &lt;asp:TextBox ID="TextBox2" runat="server" Text="&lt;%# TextFromMethod %&gt;"&gt;&lt;/asp:TextBox&gt;        
    &lt;/div&gt;   
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>it was mostly so the designer guys could use it in the aspx page. Seems like a simple thing to push a variable value into a textbox to me.</p>

<p>It's also confusing to me why</p>

<pre><code>&lt;asp:Label runat="server" ID="label1"&gt;&lt;%=TextFromString%&gt;&lt;/asp:Label&gt;
</code></pre>

<p>and</p>

<pre><code>&lt;asp:TextBox ID="TextBox3" runat="server"&gt;Hello&lt;/asp:TextBox&gt;
</code></pre>

<p>works but </p>

<pre><code>&lt;asp:TextBox ID="TextBox4" runat="server"&gt;&lt;%=TextFromString%&gt;&lt;/asp:TextBox&gt;
</code></pre>

<p>causes a compilation error.</p>

[{'answer_id': 36164, 'author': 'Toran Billups', 'author_id': 2701, 'author_profile': 'https://Stackoverflow.com/users/2701', 'pm_score': 1, 'selected': False, 'text': '<p>Have you tried using an HTML control instead of the server control?  Does it also cause a compilation error?</p>\n\n<pre><code>&lt;input type="text" id="TextBox4" runat="server" value="&lt;%=TextFromString%&gt;" /&gt;\n</code></pre>\n'}, {'answer_id': 36234, 'author': 'Mark Brackett', 'author_id': 2199, 'author_profile': 'https://Stackoverflow.com/users/2199', 'pm_score': 3, 'selected': True, 'text': "<p>There's a couple of different expression types in .ASPX files. There's:</p>\n\n<pre><code>&lt;%= TextFromMethod %&gt;\n</code></pre>\n\n<p>which simply reserves a literal control, and outputs the text at render time.</p>\n\n<p>and then there's:</p>\n\n<pre><code>&lt;%# TextFromMethod %&gt;\n</code></pre>\n\n<p>which is a databinding expression, evaluated when the control is DataBound(). There's also expression builders, like:</p>\n\n<pre><code>&lt;%$ ConnectionStrings:Database %&gt;\n</code></pre>\n\n<p>but that's not really important here....</p>\n\n<p>So, the <code>&lt;%= %&gt;</code> method won't work because it would try to insert a Literal into the .Text property...obviously, not what you want.</p>\n\n<p>The <code>&lt;%# %&gt;</code> method doesn't work because the TextBox isn't DataBound, nor are any of it's parents. If your TextBox was in a Repeater or GridView, then this method would work.</p>\n\n<p>So - what to do? Just call <code>TextBox.DataBind()</code> at some point. Or, if you have more than 1 control, just call <code>Page.DataBind()</code> in your <code>Page_Load</code>.</p>\n\n<pre><code>Private Function Page_Load(sender as Object, e as EventArgs)\n   If Not IsPostback Then\n      Me.DataBind()\n   End If\nEnd Function\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/36028', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3747/']