關於Asp.net頁面的刷新


     在Asp.net中,當你點擊button或者將gridview進行分頁,點擊頁面的時候,它們都會進行頁面刷新,或者進行postback。

     有的時候我們需要設置checkbox按鈕,比如全選,當選擇它的時候使前台整個頁面進行刷新,這個時候一定要將對應控件的autopostback 屬性設置為true

      舉例如下(當點擊全選的時候,前台頁面要進行刷新,使其他復選框都置為選擇狀態。這個時候主要要將checkbox的autopostback屬性設置為true,然后對應填入事件響應函數即可):


其他后台代碼手動刷新頁面的方法,這些方法摘自http://www.cnblogs.com/raymond19840709/archive/2007/09/11/890045.html
第一: 
private void Button1_Click( object sender, System.EventArgs e )   
{ 
    Response.Redirect( Request.Url.ToString( ) ); 

第二: 
private void Button2_Click( object sender, System.EventArgs e )   
{ 
    Response.Write( " 
    <script language=javascript>window.location.href=document.URL; 
    </script>" ); 

第三: 
private void Button3_Click( object sender, System.EventArgs e )   
{ 
    Response.AddHeader( "Refresh","0" ); 

第四: 
private void Button6_Click( object sender, System.EventArgs e )   
{ 
    Response.Write( " 
    <script language=javascript>window.location.reload( ); 
    </script>" ); 

第五:(需替換<>) 
<script><!-- 
var limit="3:00" 
if ( document.images ) 
{ 
    var parselimit=limit.split( ":" )parselimit=parselimit[0]*60+parselimit[1]*1 
} 
function beginrefresh( ) 
{ 
    if ( !document.images )returnif ( parselimit==1 )window.location.reload( )else 
    { 
        parselimit-=1curmin=Math.floor( parselimit/60 )cursec=parselimit%60if ( curmin!=0 )curtime=curmin+"分"+cursec+"秒后重刷本頁!"elsecurtime=cursec+"秒后重刷本頁!"window.status=curtimesetTimeout( "beginrefresh( )",1000 ) 
    } 
} 
window.onload=beginrefresh//-->  </script><DIV font-family: georgia, verdana, Arial, helvetica, sans-seriff; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 20px; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">LEFT: 408px; 
POSITION: absolute; 
TOP: 232px" ms_positioning="text2D"> 
<P><FONT size="3">自動刷新頁面</FONT></P> 
</DIV>

第六: 
<meta http-equiv="refresh" content="300; url=target.html">


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM