I have a variable which I get from database I want to output this variable in the aspx page in between the html. I tried to make it public but it shows some error, how can I use a variable set in page load function in its aspx page?
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.
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());
%>