development

ASP.NET에서 페이지를 어떻게 새로 고치나요?

big-blog 2020. 6. 8. 07:59
반응형

ASP.NET에서 페이지를 어떻게 새로 고치나요? (코드로 다시로드하자)


ASP.NET에서 페이지를 어떻게 새로 고치나요? (코드로 다시로드하자)

Sharepoint 내의 웹 파트 내부의 사용자 정의 컨트롤에 있기 때문에 내가 페이지가 있는지 여부를 알 수 없기 때문에 Response.Redirect ()를 사용하지 않습니다.


페이지가 클라이언트에 렌더링되면 새로 고침을 강제하는 방법은 두 가지뿐입니다. 하나는 자바 스크립트입니다

setTimeout("location.reload(true);", timeout);

두 번째는 메타 태그입니다.

<meta http-equiv="refresh" content="600">

서버 측에서 새로 고침 간격을 설정할 수 있습니다.


내 사용자 컨트롤에서 데이터를 업데이트 한 후 다음을 수행합니다.

  Response.Redirect(Request.RawUrl);    

이렇게하면 페이지가 다시로드되고 사용자 정의 컨트롤에서 정상적으로 작동합니다. RawURL을 사용 Request.Url.AbsoluteUri하고 요청에 포함될 수있는 GET 매개 변수를 유지 하지 마십시오 .

__doPostBack포스트 백을 수행 할 때 많은 aspx 페이지가 다르게 동작하므로 :을 사용하고 싶지 않을 것입니다 .


늦었을 수도 있지만 답변을 찾는 사람에게 도움이되기를 바랍니다.

다음 행을 사용하여이를 수행 할 수 있습니다.

Server.TransferRequest(Request.Url.AbsolutePath, false);

Response.Redirect프로세스의 단계가 증가하므로 사용하지 마십시오 . 실제로하는 것은 :

  1. 리디렉션 헤더가있는 페이지를 다시 보냅니다.
  2. 브라우저가 도착 URL로 리디렉션됩니다.

보시다시피, 동일한 결과에는 1 회가 아닌 2 회가 소요됩니다.


이 시도:

Response.Redirect(Request.Url.AbsoluteUri);

javascript의 location.reload () 메소드를 사용하십시오 .

<script type="text/javascript">
  function reloadPage()
  {
    window.location.reload()
  }
</script>

asp.net에서 페이지를 새로 고치는 다양한 방법이 있습니다 ...

자바 스크립트

 function reloadPage()
 {
     window.location.reload()
 }

뒤에 코드

Response.Redirect(Request.RawUrl)

메타 태그

<meta http-equiv="refresh" content="600"></meta>

페이지 리디렉션

Response.Redirect("~/default.aspx"); // Or whatever your page url

전체 페이지를 새로 고치지 않으려면 UpdatePanel 내부에서 새로 고칠 내용을 래핑 한 다음 비동기 포스트 백을 수행하는 것이 어떻습니까?


개인적으로 페이지의 상태를 유지해야하므로 모든 텍스트 상자와 기타 입력 필드가 값을 유지합니다. 메타 새로 고침을 수행하면 새 게시물과 같습니다. IsPostBack은 항상 false이므로 모든 컨트롤이 다시 초기화 된 상태입니다. 상태를 유지하려면 이것을 Page_Load () 끝에 놓으십시오. 이벤트가 연결된 butRefresh와 같은 이벤트 butRefresh_Click (...)과 같이 페이지에 숨겨진 버튼을 만듭니다. 이 코드는 사용자가 새로 고침 버튼을 클릭 한 것처럼 포스트 백을 실행하도록 페이지에 타이머를 설정합니다. 모든 상태와 세션이 유지됩니다. 즐겨! (PS 포스트 백에서 오류가 발생하면 @Page 헤더 EnableEventValidation = "false"에 지시문을 넣어야 할 수도 있습니다.

//tell the browser to post back again in 5 seconds while keeping state of all controls
ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh", "<script>setTimeout(function(){ " + ClientScript.GetPostBackClientHyperlink(butRefresh, "refresh") + " },5000);</script>");

You can't do that. If you use a redirect (or any other server technique) you will never send the actual page to the browser, only redirection pages.

You have to either use a meta tag or JavaScript to do this, so that you can reload the page after it has been displayed for a while:

ScriptManager.RegisterStartupScript(this, GetType(), "refresh", "window.setTimeout('window.location.reload(true);',5000);", true);

In your page_load, add this:

Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;

Response.Write("<script>window.opener.location.href = window.opener.location.href </script>");

You can use 2 ways for solve this problem: 1) After the head tag

<head> 
<meta http-equiv="refresh" content="600">
</head>

2) If your page hasn't head tag you must use Javascript to implement

<script type="text/javascript">
  function RefreshPage()
  {
    window.location.reload()
  }
</script>

My contact:

http://gola.vn


The only correct way that I could do page refresh was through JavaScript, many of top .NET answers failed for me.

Response.Write("<script type='text/javascript'> setTimeout('location.reload(true); ', timeout);</script>");

Put the above code in button click event or anywhere you want to force page refresh.

참고URL : https://stackoverflow.com/questions/1206507/how-do-i-refresh-the-page-in-asp-net-let-it-reload-itself-by-code

반응형