need to get the context value in top of page, where the context value will be set only at the bottom of the page?
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page Load:");
}
public string setContext(string sName, string sVal)
{
HttpContext.Current.Items[sName] = sVal;
return sVal;
}
public string getContext(string sName)
{
string sVal = "default";
if (HttpContext.Current.Items[sName] != null)
sVal = HttpContext.Current.Items[sName].ToString();
else
sVal = "empty";
return sVal;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Context in TOP ???</title>
</head>
<body>
<div>
<div id="divDest" name="divDest">
Top Content:
Get1 :<%= getContext("topcontent") %> // returns "empty", BUT I Need "value to set"
</div>
<br />
Set开发者_开发问答1 : <%= setContext("topcontent", "value to set")%> <br /> // set the value
<br />
Get2 : <%= getContext("topcontent") %><br /> // returns "value to set"
<br />
<script language="javascript">
var elval = getElementVal("divTest");
document.getElementById("divDest").innerHTML = elval;
//alert(elval);
function getElementVal(elemid) {
var elemval = document.getElementById(elemid);
return elemval.innerHTML;
}
</script>
</body>
</html>
I need to get the context value in top of page, where the context value will be set at the bottom of the page.
- Get context value ==> "empty", BUT need "something"
- Set context value to "something"
- Get context value ==> "something"
I may use JS/AJAX, where the page source the value won't be present.
BUT I need the TEXT in the View Source of the page too.Is there a way to wait for the context to set and then get, I have tried with User Control, prerender and render methods too. But I can't able to get it right.
Any idea?
Your code executes in the order that it appears.
Therefore, your getContext
call is run before the call to setContext
.
What are you trying to do?
精彩评论