Asp.net Webform Display Alert and redirect

前端 未结 4 711
清歌不尽
清歌不尽 2020-12-10 07:05

I\'m currently stuck. I have a webform with a button that registers or saves a record. What i\'d like to is have it display a javascript alert and then redirect to a page. H

4条回答
  •  囚心锁ツ
    2020-12-10 07:46

    You can't do a Response.Redirect because your javascript alert will never get displayed. Better to have your javascript code actually do a windows.location.href='default.aspx' to do the redirection after the alert is displayed. Something like this:

    protected virtual void DisplayAlert(string message)
    {
        ClientScript.RegisterStartupScript(
          this.GetType(),
          Guid.NewGuid().ToString(),
          string.Format("alert('{0}');window.location.href = 'default.aspx'", 
            message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")),
            true);
    }
    

提交回复
热议问题