Question

I am working on application where i want to pass data from one to another using Cache. On First page which is an .aspx page iI have a textbox control and one button Control. On button control click event i have written following code:

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txtName.Text.Trim()))
            {                    

                Cache["Name"] = txtName.Text;

                Response.Redirect("Test.html");
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

Now on the Target page i.e Test.html i have written following code to get cache value

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        //var name = GetParameterValues('ID');
        //var name = '<%= session.getAttribute("Name") %>';


        var name = (string)["Name"];

        alert(name);

    });

but this code is not working. Please help me.

Was it helpful?

Solution

you should get cache value from server side not client (Javascript)

So it should be:

var name = '<%=Cache["Name"] %>';

btw. your test.html should be *.aspx site that way asp engine can parse it.

Or if it's completely different app to pass data you can not use cache ! One way to do this POST or GET methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top