problem window alert java c# web form

i have a code in .net c# . it is to show a message box type, and redirect navegation to other web form (my project is with web forms) i have next code, but it don't show the message . It go directly to menu.asxc form i test...if i commente second line (response.redirect) the message is correct, and show me in the scrren but if ...two lines active don't show me teh message:  her the code:

    protected void Page_Load(object sender, EventArgs e)
    {
        string VUsus,x;
        VUsus = Session["Usuario"].ToString();
        x = ClaseValAcc.myGlobalFunction("CatAplis", VUsus);
        if (!Page.IsPostBack)
        {
            if (x == "")
            {
                Response.Write("<script>window.alert('Acceso no permitido')</script>");
                Response.Redirect("Menu.aspx");
            }
        }
    }
tenriquez39EngenierAsked:
Who is Participating?
 
iuconStefanCommented:
this is because a call to Response.Redirect will simply send a 302 Code to the Browser (page moved). The page body will not be rendered, the browser requests the next page (menu.aspx).

You could redirect the user via javascript to get your message box visible:

 Response.Write("<script langauge=\"javascript\">window.alert('Acceso no permitido')</script>");
 Response.Write("<script langauge=\"javascript\">document.location.replace('Menu.aspx')</script>");

0
 
tenriquez39EngenierAuthor Commented:
wonderfull you are great thanks allot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.