0

I am setting session variable in Page1.aspx inside document.ready As

sessionStorage.setItem('PrePayAmt', 'Some Value To Be Stored');

Now i want to get this value in Page2.aspx Page Load Event

protected void Page_Load(object sender, EventArgs e)
{
     // Get Value Here
}

I have declared script section in Page2.aspx Where i am able to get this value

<script type="text/javascript">
    $(document).ready(function () {
        var pre_pay = sessionStorage.getItem('PrePayAmt');
        alert(pre_pay);
    });
</script>

I have also got one hidden variable in Page2.aspx As

<asp:HiddenField runat="server" ID="hdnPrePayAmt" />
Shaggy
  • 5,422
  • 28
  • 98
  • 163
  • 1
    How about getting the value from hiddenField in code behind?? – User2012384 Aug 18 '14 at 07:38
  • You have to make, either post to page2, either send it on url, when you call page2. – Aristos Aug 18 '14 at 07:40
  • @Aristos : Apart from that any alternative i hate to pass it as query parameter because it is amount which i am passing. – Shaggy Aug 18 '14 at 07:43
  • @User2012384 : do i able to access then in my `page_load` event ? – Shaggy Aug 18 '14 at 07:44
  • I suggest you to update the hiddenfield's value using javascript, then you'll be able to get it back in code behind. – User2012384 Aug 18 '14 at 07:46
  • @User2012384 : I tried that but it getting set after `page_load` event. read question once again – Shaggy Aug 18 '14 at 07:52
  • Oh...Sorry...just now misunderstand your question, just now did some research, according to this article: http://stackoverflow.com/questions/10488790/access-web-storage-from-server-side-possible, it said it isn't possible to access sessionstorage from code behind, but it recommend several ways to get it, see if it helps.. – User2012384 Aug 18 '14 at 08:04

1 Answers1

0

You were correct to try and set a hidden value that gets posted back, however if you use a sever-side asp.net HiddenField (i.e. asp:HiddenField) you need to specify a ClientId="hdnPrePayAmt" setting and not just ID=

e.g.

<asp:HiddenField runat="server" ClientID="hdnPrePayAmt" />

as

<asp:HiddenField runat="server" ID="hdnPrePayAmt" />

will generate its own client-side ID for that field.

If you view your page source in the browser you will see what is going on

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202