2012-03-15 4 views
2

내 코드 숨김 파일에서 이벤트 내에서 3 초 후에 특정 페이지로 사용자를 리디렉션하는 스크립트를 실행하려고합니다. 내가 아래 setTimeout과 함께 아래의 Page.ClientScript 라인을 사용할 수 있지만, 내가 도움이 필요한 것은이 작품을 얻기 위해 실제로 setTimeout 문 안에 넣어야한다는 것입니다.이벤트에서 js 코드로 리디렉션

리디렉션에 사용하는 코드 줄은 Page.ClientScript 줄로 바꾸고 싶습니다.

미리 감사드립니다.

Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect", "setTimeout('???', 3000);", true); 

Response.Redirect(String.Format("~/Edit.aspx?id={0}", movie.MovieID), false); 

참고 : 나는 운이없이 다음 시도 :

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "setTimeout('top.location.href = " + String.Format("~/Edit.aspx?id={0}", movie.MovieID) + "', 3000);", true); 

답변

2
setTimeout("top.location.href = 'TARGET'", 3000); 

하면 리디렉션 할 URL로 TARGET을 교체합니다.

당신은 코드 숨김에서 동적으로 대상 URL을 구축 할 수 있습니다 :

string targetUrl = String.Format("/Edit.aspx?id={0}", movie.MovieID); 
string javaScript = "setTimeout(\"top.location.href = '" + targetUrl + "'\", 3000);"; 

ClientScript.RegisterStartupScript(typeof(Page), "redirect", javaScript, true); 
+0

감사합니다. 오키,하지만 URL의 일부인 동적 번호 (movieID)를 입력하는 방법은 무엇입니까? – holyredbeard

+0

나는 시도했다 : Page.ClientScript.RegisterStartupScript (this.GetType(), "alert", "setTimeout ('top.location.href ="+ String.Format ("~/Edit.aspx? id = {0}", movie.MovieID) + " ', 3000);", true); 하지만 작동하지 않는 것 같습니다 :/ – holyredbeard

+0

@ JasonCraig, 나는 새로운 코드를 게시했습니다. –

관련 문제