Show Message and redirect to other page in asp.net

Aman Sharma
0
In this article I will explain how to show pop up message and redirect on clicking “ok” button of message.



click on Image to Enlarge View

Function to Show message and Redirect to other page:

public void ShowMessage_Redirect(System.Web.UI.Page page, string Message, string Redirect_URL)
    {
        string alertMessage = "<script language=\"javascript\" type=\"text/javascript\">";

        alertMessage += "alert('" + Message + "');";
        alertMessage += "window.location.href=\"";
        alertMessage += Redirect_URL;
        alertMessage += "\";";
        alertMessage += "</script>";

        ClientScript.RegisterClientScriptBlock(GetType(),"alertMessage ", alertMessage );
     
    }


Create  small Application to Demonstrate the concept:
Add a web form in application. Now Write above function and call this function on page load. When you will run or view the page, a message will be appear. When you click on the OK button on message, it will redirect to other page.


public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ShowMessage_Redirect(this.Page, "Show message and Redirect to other page.""http://www.google.com");
    }

    public void ShowMessage_Redirect(System.Web.UI.Page page, string Message, string Redirect_URL)
    {
        string alertMessage = "<script language=\"javascript\" type=\"text/javascript\">";

        alertMessage  += "alert('" + Message + "');";
        alertMessage += "window.location.href=\"";
        alertMessage += Redirect_URL;
        alertMessage += "\";";
        alertMessage += "</script>";

        ClientScript.RegisterClientScriptBlock(GetType(),"alertMessage ", alertMessage );
     
    }

}

Post a Comment

0Comments
Post a Comment (0)

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

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