c# - asp.net 按钮类型链接应在新窗口中打开

标签 c# javascript asp.net

使用c#.net4.0

我知道类型链接的 gridview 中的 asp.net 按钮在单击时会发布到同一页面,在实际将用户重定向到外部站点之前我需要在服务器端进行多次操作,因此我无法使用超链接字段。我现在需要的是外部站点 htm 页面应该在单独的窗口中打开。我尝试了以下方法,但源站点的字体变大了???

这是我尝试过的

                       Response.Write("<script>");
                       Response.Write("window.open('http://www.google.co.uk','_blank')");
                       Response.Write("</script>");
                       Response.End();

我可能需要刷新源站点吗?

谢谢

@Curt 这是超链接的代码,我累了

在页面加载时在 gridview 上添加了新按钮

HyperLinkField LinksBoundField = new HyperLinkField();          
        string[] dataNavigateUrlFields = {"link"};
        LinksBoundField.DataTextField = "link";
        LinksBoundField.DataNavigateUrlFields = dataNavigateUrlFields;
        LinksBoundField.DataNavigateUrlFormatString = "http://" + Helper.IP + "/" + Helper.SiteName + "/" + Helper.ThirdPartyAccess + "?dispage={0}&token=" + Session["Token"]; 
        LinksBoundField.HeaderText = "Link";
        LinksBoundField.Target = "_blank";           

        GridViewLinkedService.Columns.Add(LinksBoundField);
        GridViewLinkedService.RowDataBound += new GridViewRowEventHandler(grdView_RowDataBound);


to append external values (refe and appid) to navigate url


       protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                string strvalue = "";
                string strvalue1 = "";
                string strRef = "";
                string strAppId = "";
                foreach (GridViewRow row in GridViewLinkedService.Rows)
                {

                    if (row.RowType == DataControlRowType.DataRow)
                   {
                        //reference and appid
                        strAppId = row.Cells[0].Text;
                 strRef = row.Cells[1].Text;
            HyperLink grdviewLink = (HyperLink)row.Cells[5].Controls[0];
             strvalue = grdviewLink.NavigateUrl;
     strvalue1 = Regex.Replace(strvalue, "(.*dispage\\=).*/(services.*)", "$1$2");
         grdviewLink.NavigateUrl = "~/My Service/FillerPage.aspx?nurl=" + strvalue1 + "&AppID=" + strAppId.ToString() + "&Ref=" + strRef.ToString();


                  }
               }
            }

 public partial class FillerPage : System.Web.UI.Page
    {
       private string refno = null;
       private string appid = null;
       private string nurl = null;
       private string strvalue1 = "";
       private string newtoken = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.GetValues("AppID") != null)
            {
                appid = Request.QueryString.GetValues("AppID")[0].ToString();
            }

            if (Request.QueryString.GetValues("Ref") != null)
            {
                refno = Request.QueryString.GetValues("Ref")[0].ToString();
            }

            if (Request.QueryString.GetValues("nurl") != null)
            {
                nurl = Request.QueryString.GetValues("nurl")[0].ToString();
            }

        while receiving the long url it gets messed up(same query multiple times and all jumbled up)?????

有没有更好的方法来传递参数???

最佳答案

您需要注册脚本而不是response.write

所以适合您的代码是:

ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=JavaScript>window.open('http://www.google.co.uk','_blank')</script>");

了解更多:ClientScriptManager.RegisterStartupScript .

关于c# - asp.net 按钮类型链接应在新窗口中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397215/

相关文章:

c# - WPF 全屏切换仍然显示桌面的一部分

c# - 从数据库中获取单个随机值

javascript - 如何使用 JavaScript 将呈现的网页另存为图像?

asp.net - Visual Studio 2010 下 ASP.NET Response.Redirect 中重复的虚拟路径

asp.net - ASP.NET Core MVC 中 Layout.cshtml 中的访问请求或 IQueryCollection?

c# - 调用 DevExpress ASPxGridViewExporter.WriteXlsxToResponse 方法时出现错误 "The thread was being aborted."

javascript - 在网页上进行文本替换的最简洁方法? (使用 GreaseMonkey)

javascript - PinchZoom.js 与 iOS 设备上的 Owl Carousel 不兼容

asp.net - 如何在索引和编辑 View (强绑定(bind))中传递和合并 MVC3 中的两个模型?

c# - Objective-C 与 C# 相比如何?