ASP.NET Presist changes on a div during postback?
I'm using jquery to toggle a div on and off...It works fine however开发者_如何学Python, 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
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>
精彩评论