Jason
Jason

Reputation: 21

ASP.NET Presist changes on a div during postback?

I'm using jquery to toggle a div on and off...It works fine however, when a postback happens on the page, the changes are not saved. How can I save the changes. Any help would be appreciated.

Thanks,

Jason

Upvotes: 2

Views: 438

Answers (1)

Madhur Ahuja
Madhur Ahuja

Reputation: 22709

Javascript is purely a client side language (although some things like AJAX requests can be done with it). Any changes you make to the page using javascript (ie. the visibility of divs) will not be kept when a postback is performed.

you can use hidden control to store the client property before reset. In Page_Load you can retrieve the value from hidden control and register the JavaScript to reserve the client property.

There is a sample code.

HTML code:

<script type="text/javascript">
function Button2_onclick() {

    if(document.getElementById('Hidden1').value=='block')
    {
    document.getElementById('div1').style.display='none';
    document.getElementById('Hidden1').value='none';
    }
    else
    {

    document.getElementById('div1').style.display='block';
    document.getElementById('Hidden1').value='block';
    }
}

</script>

Upvotes: 2

Related Questions