0

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.

Sunny Sandeep
  • 971
  • 7
  • 18
  • 53

1 Answers1

1

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.

Kamil Lach
  • 4,519
  • 2
  • 19
  • 20
  • It is workin gin ..aspx page,but is there any way to achieve using javascript in html page. – Sunny Sandeep May 10 '14 at 09:10
  • well i think u can use GET method so redirect to Test.html?myValue=Value, try to get this value from Javascript, there is an example of that: http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter – Kamil Lach May 10 '14 at 09:13
  • But i do not want to use querystring. Is there any another method to achieve my goal. – Sunny Sandeep May 10 '14 at 09:28
  • you can still use *.aspx page and use url rewrite engine of your web serwer, thay way user can see your page as test.html – Kamil Lach May 10 '14 at 11:40