I need to initialize the text attribute of the text box element with a property from some where else when actually I can simply do this from code but it will be much m
Option 1: don't use server controls
If you aren't accessing the value on the server, just use plain HTML instead of an ASP.NET server control:
Option 2: use Page.DataBind()
If you change your code to use <%#
instead of <%=
(as below) and call Page.DataBind()
, it will work (I've tested it). Change your markup to this:
" />
And in your logic, call Page.DataBind()
in the Load event like this:
protected void Page_Load(object sender, EventArgs e) {
Page.DataBind();
}
Even though the TextBox is not contained in a typical "data bound" control such as a Repeater or GridView, calling DataBind()
on a control will force it to evaluate <%# ... %>
statements.
The Moof's comment (below) is correct. This post also mentions Page.DataBind().