如何使用asp.net中的imagebutton click事件转到另一个webiste [英] How to goto another webiste using imagebutton click event in asp.net

查看:97
本文介绍了如何使用asp.net中的imagebutton click事件转到另一个webiste的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我发布了一个网站,当我点击按钮时有一个图像按钮,它必须转到一些网页页面。



例如:我点击图片按钮它已经转到http://www.google.com







但它显示如下错误:

hi friends i am publish one website in that having one image button when i am click on button it has to goto some url page..

example: when i am click on image button it has goto http://www.google.com



but it was shows error like this :

Invalid path for child request 'http://www.google.com'. A virtual path is expected.





请帮帮我......紧急......



我尝试过的事情:



我的代码是:



please help me ..it's urgent...

What I have tried:

my code is :

protected void imgbtn_Click(object sender, ImageClickEventArgs e)
   {
        Server.Transfer ("http://www.google.com");
   }

推荐答案

Server.Transfer转移到服务器上的另一个链接。您应该尝试

Response.Redirect(链接)。



但更好的解决方案是(假设您在重定向之前没有完成其他处理)创建包含href指向目标站点的图像的锚元素。这样你就没有服务器往返,只是链接的默认行为。
Server.Transfer is transfer to another link on the server. You should try
Response.Redirect(link).

But better solution would be (assuming you have no other processing done before redirect) to create anchor element containing the image with href pointing to your target site. That way you have no server round trip, just default behaviour of the link.


这篇关于如何使用asp.net中的imagebutton click事件转到另一个webiste的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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