【问题标题】:Problem while Open New Tab from Code Behind in asp.net在 asp.net 中从代码后面打开新选项卡时出现问题
【发布时间】:2020-01-13 19:08:10
【问题描述】:

希望你们都做得很好! 我的任务是单击按钮在新选项卡中打开页面。 让我证明一下,

<asp:Button runat="server" ID="btnCreateQuestion" Text="Create Question" CssClass="btn btn-primary" OnClick="btnCreateQuestion_OnClick" OnClientClick="SetTarget();" />



   function SetTarget() {
            debugger;
            document.forms[0].target = "_blank";
        }

   protected void btnCreateQuestion_OnClick(object sender, EventArgs e) {
 // other code ....
 switch (questionType) {
  case "Multiple Choice":
   Response.Cookies["options"].Value = optionNumber;
   Response.Redirect("~/Products/McQType.aspx?scode=" + subjectcodeid);
   break;
 }
}  

现在此代码按预期工作,即页面正在新选项卡中打开...

现在我有一个网格,在该网格内我有一个按钮,它负责相同的功能,即在新选项卡中打开页面..

//button located inside grid
    <asp:LinkButton CssClass="btn" ID="btnEditQuestion" runat="server"
                                                            Style="padding-right: 10px; font-size: 11px; letter-spacing: -0.1px; font-family: Arial,Helvetica,sans-serif !important; font-weight: bold !important;"
                                                            OnClick="btnEditQuestion_OnClick"
                                                            OnClientClick="SetTarget();">
                                                            Edit Question
                                                            <i class="fa fa-edit" aria-hidden="true"></i>
                                                        </asp:LinkButton> 


protected void btnEditQuestion_OnClick(object sender, EventArgs e) {
 {
  case "Multiple Choice":
  Response.Redirect("~/Products/McQType.aspx?qid=" + questionId);
  break;
 }
}

现在页面正在打开但不在新标签中,它应该在新标签中打开..

如何解决这个问题?

【问题讨论】:

    标签: asp.net webforms


    【解决方案1】:
    using System.Web.UI;
        protected void btnEditQuestion_OnClick(object sender, EventArgs e) {
         {
          case "Multiple Choice":
          ScriptManager.RegisterStartupScript(this, typeof(string), "", 
         "window.open('~/Products/McQType.aspx?qid=" + questionId + "', '', '');", true);
          break;
         }
        }
    

    【讨论】:

    • 感谢您的回复兄弟,我已经这样做了,但我想知道为什么我的代码在第二种情况下不起作用..aspsnippets.com/Articles/…
    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 2015-06-29
    • 2013-09-17
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多