【问题标题】:Window location to another page with parameters带有参数的另一个页面的窗口位置
【发布时间】:2016-09-09 08:08:27
【问题描述】:
string parameter = Request.QueryString["forum_id"];

ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Replied!Thank you.');window.location ='eforum_main.aspx?forum_id='+parameter;", true);

我尝试在重定向时添加参数但失败,不知道我做错了什么,我的页面在我提交数据后没有重定向到该页面。

【问题讨论】:

    标签: javascript c# asp.net webforms


    【解决方案1】:

    您没有在 ScriptManager 中正确使用 parameter 字符串。

    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Replied!Thank you.');window.location ='eforum_main.aspx?forum_id=" + parameter + "';", true);
    

    【讨论】:

      【解决方案2】:

      您只是将+parameter; 作为纯文本写入 javascript,为避免混淆,您可以使用 string.Format:

      string
          parameter = Request.QueryString["forum_id"],
          JavaScriptCommand = "alert('Replied!Thank you.');" + string.Format(
              "window.location='eforum_main.aspx?forum_id={0}';",
              parameter
          );
      
      ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", JavaScriptCommand , true);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-04
        • 1970-01-01
        • 2018-08-14
        • 2017-11-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多