如何使用图像按钮在另一个窗口中打开网址
您好,我知道如何通过设置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果这不起作用,请尝试将其添加到您的 ImageButton 中:
If that doesn't work, try adding this to your ImageButton:
我只是弄清楚......
在
Page_Load
事件中,输入然后例如在图像按钮
Click
事件中,输入:它只会在新选项卡中打开此页面。尝试一下:)
I just figure it out..
On
Page_Load
event, putThen for example in a image button
Click
event, you put:It will simply open this page in a new tab. Try it :)
您可以使用属性集合添加“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
将 target="_blank" 添加到 onClientClick 即可解决问题
Add target="_blank" to onClientClick will do the trick
在后面的代码中。
你就完成了。
In the code behind.
And you're done.
试试这个:
Try this:
这样,客户端可以在新页面中看到他想要的内容,因为服务器和可用的内容以及他在站点中的帐户在页面加载开始时可用
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