문제

파일 뒤의 코드에서 Java 스크립트를 표시 해야하는 기능을 구현 한 다음 사용자가 다른 페이지로 리디렉션해야합니다.

i 를 모두 사용했습니다.

this.Context.Response.Write("<script type='text/javascript'>alert('some text')</script>");
.

ClientScriptManager.RegisterStartupScript();
.

그러나 그들 중 누구도 경고 상자를 보여주지 않았습니다. 코드 스 니펫은 다음과 같습니다 :

//approach 1
    this.Context.Response.Write("<script type='text/javascript'>alert('some text')</script>");
  SPUtility.Redirect(string.Empty, SPRedirectFlags.UseSource, this.Context);

//approach 2
String csname1 = "PopupScript";
                Type cstype = this.GetType();

                // Get a ClientScriptManager reference from the Page class.
                ClientScriptManager cs = Page.ClientScript;

                // Check to see if the startup script is already registered.
                if (!cs.IsStartupScriptRegistered(cstype, csname1))
                {
                    StringBuilder cstext1 = new StringBuilder();
                    cstext1.Append("<script type=text/javascript> alert('You do not have Access to perform any action.') </");
                    cstext1.Append("script>");

                    cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
                }
  SPUtility.Redirect(string.Empty, SPRedirectFlags.UseSource, this.Context);
.

그러나 그 중 누구도 알림 상자를 보여줍니다

제발 도와주세요

도움이 되었습니까?

해결책

The script will never make it to the client because of the redirect. You either need to send the script with the alert and then postback to perform the redirect (yuck) or perform the redirect in the script by doing a location.replace to the URL you want to redirect to...you could also set location.href to the URL as well.

So you could do something like this:

ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptname", "alert('some message'");location.replace('url to redirect to');", true);

다른 팁

These methods registers and adds the script block to the page. So it will fire after the page is rendered from the server. In your case you are redirecting to some other page while the script is registered on the previous page.

So it would not fire on the previous page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top