make them server controls, they will normally keep the state, for example<input type=text runat=server id='txt'><input type=hidden runat=server id='hid'>
you need to use form elements to keep the state, when you 用JS向DIV中innerHTML的一些数据, also save the html into a hidden input control<input type=hidden id=hid runat=server />document.forms[0].elements["hid"].value = YourDiv.innerHTML;and reload your div with the value in this control upon postbackfunction window.onload() { YourDiv.innerHTML= document.forms[0].elements["hid"].value; }
试试在Page_Load里加上这个判断 if (!IsPostBack) { //loadData......}
{
YourDiv.innerHTML= document.forms[0].elements["hid"].value;
}
if (!IsPostBack)
{
//loadData......}
1、假设你的innerHTML是固定的,或者页面一加载就设定的。那么这样来:
<body onload="your_function()">
<script language="javascript">
function your_function
{
……
}
2、假设你的innerHTML是后来加入的,那么在内容不多的前提条件下,可以将这些内容用js写入cookie中——你需要认真参考javascript对cookie操作的知识。这个解决方案仅限于你的innerHTML不大的情况下; 思归大哥给的办法也不错,楼主可以多多参考。