need to get the context value in top of page, where the context value will be set only at the bottom
Posted
by Mahadevan Alagar
on Stack Overflow
See other posts from Stack Overflow
or by Mahadevan Alagar
Published on 2010-03-24T13:33:53Z
Indexed on
2010/03/24
13:43 UTC
Read the original article
Hit count: 355
<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 />
Set1 : <%= 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?
© Stack Overflow or respective owner