showing ClientScript Alerts before Redirecting to another page in ASP.NET c#?

大城市里の小女人 提交于 2019-12-04 10:00:20

This is what I have for my projects:

public static void jsAlertAndRedirect(System.Web.UI.Page instance, string Message, string url)
{
    instance.Response.Write(@"<script language='javascript'>alert('" + Message + "');document.location.href='" + url + "'; </script>");
}

I use it like this from a page:

HTMLHelper.jsAlertAndRedirect(this, "This is an alert.", ResolveUrl("~/Default.aspx"));

Good luck.

  string  strScript = "<script>"+"alert('The User has been added successfully.');";
                strScript += "window.location='AdminPanel.aspx';";
                strScript += "</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Startup", strScript);
Subrat Kumar Hota
 string strScript = "&lt;script &gt;alert('The User has been added successfully.');                 window.location='AdminPanel.aspx';&lt; /script &gt;";
 Page.ClientScript.RegisterStartupScript(this.GetType(), "Startup",strScript);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!