0

我在这里工作在 asp.net 上。我需要从那里打开我的 url 到我的新窗口,我提供了我的用户 url 和密码,我需要登录到一个特定的站点。

一切正常,问题是它没有在新窗口中打开,但我在谷歌搜索过我没有文章,但我没有做错什么来打开一个窗口。我已经尽力了,但我只是卡住了。

这是我尝试过的:这里我有一个链接按钮,你可以在这里查看,我已经成功登录到我的网站,但我需要在新窗口中打开它

<asp:LinkButton  runat="server" Text='new window'  onclick="btnlink_Click"></asp:LinkButton>

我的页面代码后面的代码在这里:

public void btnlink_Click(object sender, EventArgs e)
        {
            CrossPost cp = new CrossPost();          
            cp.AddField("username", "saddusattu");
            cp.AddField("password", "password");
            cp.PostDataToForm(Url: "http://www.Estateslogin/index.php", FormName: "form",OpenLinkNewWin:true);    

        }

我正在调用以下方法:

 public void PostDataToForm(string Url, string FormName, bool OpenLinkNewWin)
            {

                try
                {
                    var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";

                    var win =  "_blank";
                    string newwindow = "<script>window.open('" + Url + "','" + win + "', '" + strWindowFeatures + "');</script>";

                    if (OpenLinkNewWin)
                    {
                        System.Web.HttpContext.Current.Response.Write(newwindow);
                    }     

                    System.Web.HttpContext.Current.Response.Clear();

                    System.Web.HttpContext.Current.Response.Write("<html><head>");
                    System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\"  method='post'  action=\"{2}\" >", FormName, "post", Url));
System.Web.HttpContext.Current.Response.Write("</form>");

            System.Web.HttpContext.Current.Response.Write("</body></html>");
                    System.Web.HttpContext.Current.Response.End();
}

上面的代码必须在新窗口中打开,System.Web.HttpContext.Current.Response.Write这就是我遇到问题的原因。

4

1 回答 1

0

有六个名为 的函数RegisterClientScriptBlock,每个函数的用途和用例略有不同。其中之一可能就是您想要的。例如,如果LinkButton在更新面板中并且您使用的ScriptManager是静态函数,ScriptManager.RegisterClientScriptBlock那么它可能会运行良好。

于 2013-11-06T18:21:05.137 回答