如何使用图像按钮在另一个窗口中打开网址

发布于 2024-11-02 10:47:45 字数 825 浏览 1 评论 0原文

您好,我知道如何通过设置 target = _blank 在超链接中实现此目的,我如何使用图像按钮控件来做到这一点,下面是我的代码:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" />

             <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtPostcode1" ErrorMessage="Postcode is required"  ValidationGroup="group2"></asp:RequiredFieldValidator>
            <br />

代码隐藏:

    protected void test_Click(object sender, ImageClickEventArgs e)
{

    Response.Redirect(String.Format("http://maps.google.co.uk/maps?saddr={0}&daddr=&daddr=Wigan+WN6+0HS,+United+Kingdom&iwloc=1&dq=Tangent+Design", txtPostcode1.Text));



}

任何帮助或建议将不胜感激

Hi I know how to acheive this in hyperlink by setting target = _blank , how can i do this using image button control , below is my code:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" />

             <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtPostcode1" ErrorMessage="Postcode is required"  ValidationGroup="group2"></asp:RequiredFieldValidator>
            <br />

Code behind:

    protected void test_Click(object sender, ImageClickEventArgs e)
{

    Response.Redirect(String.Format("http://maps.google.co.uk/maps?saddr={0}&daddr=&daddr=Wigan+WN6+0HS,+United+Kingdom&iwloc=1&dq=Tangent+Design", txtPostcode1.Text));



}

Any help or advice will be highly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

不羁少年 2024-11-09 10:47:45
protected void Page_Load() {
   ControlID.Attributes.Add("target", "_blank");    
}

如果这不起作用,请尝试将其添加到您的 ImageButton 中:

<asp:ImageButton runat="server" OnClientClick="window.open('http://url/to/open');" ></asp:ImageButton>
protected void Page_Load() {
   ControlID.Attributes.Add("target", "_blank");    
}

If that doesn't work, try adding this to your ImageButton:

<asp:ImageButton runat="server" OnClientClick="window.open('http://url/to/open');" ></asp:ImageButton>
呆° 2024-11-09 10:47:45

我只是弄清楚......

Page_Load 事件中,输入

    this.Form.Target = "_blank"; // Will set all link's target to a new window

然后例如在图像按钮 Click 事件中,输入:

    Response.Redirect("http://stackoverflow.com");

它只会在新选项卡中打开此页面。尝试一下:)

I just figure it out..

On Page_Load event, put

    this.Form.Target = "_blank"; // Will set all link's target to a new window

Then for example in a image button Click event, you put:

    Response.Redirect("http://stackoverflow.com");

It will simply open this page in a new tab. Try it :)

滴情不沾 2024-11-09 10:47:45

您可以使用属性集合添加“target”,“_blank”,

这应该将目标属性添加到图像周围的锚链接

you could use the Attributes collection to add "target","_blank"

this should add the target attribute to the anchor link surrounding the image

痴情换悲伤 2024-11-09 10:47:45

target="_blank" 添加到 onClientClick 即可解决问题

Add target="_blank" to onClientClick will do the trick

他夏了夏天 2024-11-09 10:47:45

在后面的代码中。

imgbtn.OnClientClick = "target='blank'";

你就完成了。

In the code behind.

imgbtn.OnClientClick = "target='blank'";

And you're done.

似最初 2024-11-09 10:47:45

试试这个:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" OnClientClick="form1.target ='_blank';" />

Try this:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" OnClientClick="form1.target ='_blank';" />
心在旅行 2024-11-09 10:47:45
this.Form.Target = "_blank"; 

这样,客户端可以在新页面中看到他想要的内容,因为服务器和可用的内容以及他在站点中的帐户在页面加载开始时可用

this.Form.Target = "_blank"; 

This way the client can see what he wants in a new page, since the server and what is available and his account in the site available at the beginning PageLoad

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文