如何在新窗口中打开列表框项目的网站地址 [英] how to open listbox items website address in new window

查看:79
本文介绍了如何在新窗口中打开列表框项目的网站地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,列表框和两个按钮.当我单击button1时,输入的网址将移动到列表框.就像在列表框中添加多个网址.现在,当我单击第二个按钮时,列表框中的地址会在多个新窗口中打开.我的代码是:

I have a text box, list box and two button. When I click button1 the webaddress entered is moved to listbox. Like that by adding more than one webaddress to list box.Now when I click second button the address in list box open in multiple new window. My code is:

<table>
    <tr>
    <td>
    <asp:TextBox ID="txtMail" runat="server"></asp:TextBox>
    </td>
    <td>
    <asp:ListBox id="List" runat="server" ></asp:ListBox>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:Button ID="btnClick" Text="Click" runat="server"/>
    </td>
</table>



在后面的代码中



In code behind

protected void Button1_Click(object sender, EventArgs e)
{
   List.Items.Add(txtMail.Text);
}

protected void btnClick_Click(object sender, EventArgs e)
{
  //what can i do here
}



通过使用javascript手段,告诉我代码



by using javascript means tell me the code

推荐答案

您要使用Response.Reidrect并指定目标框架/窗口.我用Google搜索了"asp.net响应目标",这是返回的460万以上结果之一:

You want to use Response.Reidrect and specify the target frame/window. I googled "asp.net response target", and this was one of the more than 4.6 MILLION results returned:

public static class ResponseHelper 
{
    public static void Redirect(this HttpResponse response, string url, string target, string windowFeatures)      
    {
        if ((String.IsNullOrEmpty(target) || target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))          
        {  
            response.Redirect(url);
        }
        else
        {
            Page page = (Page)HttpContext.Current.Handler;
            if (page == null)
            {
                throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
            }
            url = page.ResolveClientUrl(url);
            string script;
            if (!String.IsNullOrEmpty(windowFeatures))
            {
                script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
            }
            else
            {
                script = @"window.open(""{0}"", ""{1}"");";
            }
            script = String.Format(script, url, target, windowFeatures);
            ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
        }      
    } 
} 



这样,您就可以对实际的Response对象进行很好的覆盖



With this you get nice override on the actual Response object

Response.Redirect(redirectURL, "_blank", "menubar=0,scrollbars=1,width=780,height=900,top=10"); 



Google会显示所有内容.



Google reveals all.


您好,
您可以采用javascript列表框中显示的网址.

代码如下
HTML:

Hi,
u can take url present in list box in javascript.

code as follows
HTML :

<select id="ssPayMode"  önchange="ViewiNewWindow(this.value);"  runat="server">
                                        <option value="www.google.com">your url</option>
                                        <option value="www.yahoo.com">your url</option>
                                    </select>



Javascript:



Javascript:

function ViewiNewWindow(val)
{
   var url = val;
   window.open(url ,''mywindow'',''width=400,height=200,left=0,top=100,screenX=0,screenY=100'')
}




在列表框更改时调用此方法.您可以按一下单击的相同方法.




this method is called on listbox change. same way u can do on click.


这篇关于如何在新窗口中打开列表框项目的网站地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆