views:

23

answers:

1
<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"&gt;
<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.

  1. Get context value ==> "empty", BUT need "something"
  2. Set context value to "something"
  3. 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?

A: 

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?

SLaks
I need a mechanism of rendering in the top of the page, may be a control or a place holder, etc., ONLY after the "topcontent" context is set in the bottom of the page.
Mahadevan Alagar
Why don't you set it in the top of the page?
SLaks
Since only in the bottom of the page, the custom control has to be displayed which sets the context value. But the same I may call in the Page Load, which will do double process, which is already a complex and time consuming process.A Simple JS function can copy the inner html of the bottom div into the top div, will resolve the page display. Or an AJAX call at the end of the page, can set the display content in the browser.But, if I need it in the view source of the page in the top part, becomes an issue here. Hope you understand my problem?
Mahadevan Alagar