asp.net 頁面重新整理重是有問題 , 收藏幾種方法挺有用的 . 第一:
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.οnlοad=beginrefresh//--> </script> <DIV style="Z-INDEX: 102;
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"> 用window.location.href實作重新整理另個架構頁面
在寫 ASP.Net 程式的時候,我們經常遇到跳轉頁面的問題,我們經常使用 Response.Redirect ,如果客戶要在跳轉的時候使用提示,這個就不靈光了,如:
Response.Write("<script>alert(' 恭喜您,注冊成功! ');</script>");
Response.Redirect("main.html");
這時候我們的提示内容沒有出來就跳轉了,和 Response.Redirect("main.html"); 沒有任何差別。
這時我們采用下面代碼試驗一下:
Response.Write("<script language=javascript>alert(' 恭喜您,注冊成功! ')</script>");
Response.Write("<script language=javascript>window.location.href='main.html'</script>");
這個即實作了我們的要求,在提示後,跳轉頁面。
最重要的是 window.location.href 語句可以實作一個架構的頁面在執行伺服器端代碼後重新整理另一個架構的頁面 (Response.Redirect 無法達到,至少我沒有發現 ) :
如: index.htm 頁面中有二個架構,分别為 frameLeft 和 frameRight ,在 frameRight 頁面中執行伺服器端代碼後重新整理 frameLeft 中的頁面。
先前最常見的是注冊之後,自動重新整理登陸框,讓登陸框換成已登陸頁面,隻要在注冊成功的代碼之後加上一段,即可以實作重新整理另個架構的頁面。代碼如下:
Response.Write("<script language=javascript>alert(' 恭喜您,注冊成功! ')</script>");
Response.Write("<script language=javascript>window.parent.frameLeft.location.href='main.html'</script>");