Navigate to a new page and display an alert box

后端 未结 1 1028
既然无缘
既然无缘 2021-01-27 03:02

I am developing an application by using ASP.Net WebForm. Once user click a button, application will navigate to a new page and prompt out a dialog box \"Welcome to JackiesGame\"

相关标签:
1条回答
  • 2021-01-27 03:44

    Add the following in page 2. On the page load it will register only for the first time the page loads the script.

    protected void Page_Load(object sender, EventArgs e)
    {
       if(!Page.IsPostBack)
       {
        var reg = Request["Welcome"]
           if(reg != null && reg.ToString() == "yes"){
              ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", "alert('Insert Successfully')", true);
          }
       }
    }
    

    All code after the redirect is getting ignored since it has to redirect to a new page. So the code never gets triggered.

    EDIT Added a example of how it can look further

    void cmdCancel_Click(object sender, EventArgs e)
    {
        string myUrl = Globals.NavigateURL(TabId)+"?Welcome=yes";
        HttpContext.Current.Response.Redirect(myUrl, true);
    }
    
    0 讨论(0)
提交回复
热议问题