Show alert & redirect to other page in (c#) .

Aman Sharma

Sometimes, we need to redirect to list page after saving data on other page. When you click on submit button, a successful message will appear and on click on “OK” button, it will redirect to list page where we’ll show all added items.


Function to show alert message & redirect to other page on button click:


First alert will show then on click on Ok button it will redirect to desired page:


public void ShowMessage_and_Redirect(System.Web.UI.Page page, string Message, string Redirect_URL)



            string alertScript = "<script language=\"javascript\" type=\"text/javascript\">";


            alertScript += "alert('" + Message + "');";

            alertScript += "window.location.href=\"";

            alertScript += Redirect_URL;

            alertScript += "\";";

            alertScript += "</script>";


            //if (page.IsClientScriptBlockRegistered("alertredirect"))


            page.RegisterClientScriptBlock("alertredirect", alertScript);





How to call this function on button click:


private void SaveRecord()


 //Code to save data

  ShowMessage_and_Redirect(this.Page, "Student details submitted successfully""listStudent.aspx");


Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !