ASP.NET - Passing a C# variable to HTML

All of this is assuming that this is just a textbox somewhere on your page, rather than in a DataBound control. If the textbox is part of an itemTemplate in a repeater, and Child_ID is something that differes by data row, then all of this is incorrect.

Do this instead:

<asp:TextBox ID="TextBoxChildID"  runat="server" Enabled="false"><%= Child_ID %></asp:TextBox>

In short, you're making the same mistake I was making when I asked this question: Why <%= %> works in one situation but not in another


Alternatively, in code-behind, you can have this in your ASPX:

<asp:TextBox ID="TextBoxChildID"  runat="server" Enabled="false"></asp:TextBox>

and this in your Code-Behind:

TextBoxChildID.Text = Child_ID;

The variable must be public first. And:

'<%# Child_ID %>' 

Tags:

C#

Asp.Net