Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
In asp.net page by entering the below mentioned code BROWSER is only showing the message but what if i want to ADD Buttons which i created like --> OK and CANCEL and on OK button i have to write some code?     

    if (isUpdateXMLReportDataSuccess == true)
        {        
            Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");
    Response.Redirect("./ManageDefects.aspx");   
        }
        else
        {Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug not created successfully." + "')</SCRIPT>"); return;}


Also here i want to ask that in my case if the isUpdateXMLReportDataSuccess  is TRUE So according to code browser first should need to showing the message i.e "Bug created successfully." and then it should  Re-directly Redirect("./ManageDefects.aspx");

But in my case it goes to `Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");` but not showing the message on BROWSER and directly goes to Response.Redirect("./ManageDefects.aspx");


ITS NOT SHOWING THE BROWSER MESSAGE.


What I have tried:

In my case it goes to `Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");` but not showing the message on BROWSER and directly goes to Response.Redirect("./ManageDefects.aspx");


ITS NOT SHOWING THE BROWSER MESSAGE
Posted
Updated 9-Mar-16 23:22pm
Comments
Sreekanth Mothukuru 9-Mar-16 9:20am    
Instead of directly calling alert and redirect... write a JavaScript method and depending on the situation show window.confirm or ok, Cancel and do accordingly.. if needed write jQuery get/post ajax method for any async operations upon user confirmation.

Calling Response.Redirect is basically saying "throw away this page, and go directly to this one". So that's what the system does. It throws away all the HTML you have built for the page (instead of sending it to the browser when you have finished assembling it) and immediately loads a new page. It's like starting to drive to the shops and deciding half way to go see a friend instead. The distance you have driven is ignored, and a new course to your friend's house is immediately started.
If you want an alert, don't call Response.Redirect!
 
Share this answer
 
Hi,

I got the solution for above issue

C#
Instead of using this code.
 Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");
Response.Redirect("./ManageDefects.aspx"); 



 Use this one.
    ScriptManager.RegisterStartupScript(this, typeof(string), "redirect", "alert('message goes here'); window.location='" + Request.ApplicationPath + "/foldername/pagename.aspx';", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900