First way
You place a Literal control in the point you want to display the variable and then you set on PageLoad this value to the Literal Control
<asp:Literal runat="server" id="txtValueA" EnableViewState="false" />
and on code behind.
txtValueA.Text = "one of the basic";
This way you have also more control over what you try to render out.
Second way
The other way is to make it public as you say and print it when the page render. This is a different way, but not a better one.
public string cMyValue = "some string here";
and on aspx page
<%=cMyValue%>
This way you get the parameter when the page renders at run time and send this in run time on the Client.
If you try this way inside an updatepanel, then the update is fail because the update panel can not read and render again the full page but only the code behind.
Try to avoid this way, and use it only when you really needed it because this make a call to the code the moment its try to render the page and change the page...
One idea to use this way is when you have some extra calculation that you like to make, you flush the content and then you call a function with extra time cost. For example.
<%
Response.Flush();
Response.Write(CallATimeConsumeFunctionThatReturnString());
%>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…