将LinkBut​​tons用作超链接是不好的做法吗?

时间:2021-02-14 00:02:23

I have a web app with a start page composed of various links. I used the LinkButton control of System.Web.UI.WebControls for these links. I do a little bit of processing on postback, then I redirect to the appropriate page. The problem I find is that in IE7 I cannot right click the "link" and open in a new tab. The postback occurs and the new page appears, but in the current tab, not a new one! I tried the web app in chrome as well, and chrome doesn't even give the option when right clicking the link.

我有一个Web应用程序,其中包含由各种链接组成的起始页面。我使用System.Web.UI.WebControls的LinkBut​​ton控件来获取这些链接。我在回发上做了一些处理,然后我重定向到适当的页面。我发现的问题是在IE7中我无法右键单击“链接”并在新选项卡中打开。发生回发并显示新页面,但在当前选项卡中,不是新页面!我也尝试使用chrome中的web应用程序,并且在右键单击链接时chrome甚至没有提供选项。

It appears that if the destination page might need to be opened in a new tab by the user, I need to use a hyperlink or the hyperlink control. However, it would be nice if I still had the option to do some processing before jumping to that link.

看来如果用户需要在新标签页中打开目标页面,我需要使用超链接或超链接控件。但是,如果我仍然可以选择在跳转到该链接之前进行一些处理,那将是很好的。

3 个解决方案

#1


Typically it is bad practice to use a LinkButton like a normal hyper link, and even a worse idea to do a 302 redirect after the POST back has occurred.

通常情况下,使用类似普通超链接的LinkBut​​ton是不好的做法,甚至更糟糕的做法是在POST返回发生后进行302重定向。

  1. For one thing it breaks the browser interaction which you have already found.
  2. 首先,它打破了您已经找到的浏览器交互。

  3. But more importantly it breaks search engine indexing of your site, if you have an external site.
  4. 但更重要的是,如果您有外部网站,它会破坏您网站的搜索引擎索引。

Also you still can do some pre-processing on an actual hyperlink, but you just do it in a different manor. If you tell us what you are doing maybe we can help find a better way.

您还可以对实际超链接进行一些预处理,但您只需在不同的庄园中进行预处理。如果你告诉我们你在做什么,我们可以帮助找到更好的方法。

#2


You could use a HyperLink to some intermediate page and pass some querystring parameters. And then do your redirect in the pageload of the intermediate page. That way you could still open up the links in a new tab or window.

您可以将HyperLink用于某个中间页面并传递一些查询字符串参数。然后在中间页面的页面加载中进行重定向。这样你仍然可以在新的标签页或窗口中打开链接。

#3


Why not just pass querystrings with the data you need? Posting back, then redirecting not only kills performance (2x as many round trips for the client), but it reeks of bad design.

为什么不用你需要的数据传递查询字符串?发回,然后重定向不仅会导致性能下降(客户端往返次数的2倍),但它的设计很糟糕。

#1


Typically it is bad practice to use a LinkButton like a normal hyper link, and even a worse idea to do a 302 redirect after the POST back has occurred.

通常情况下,使用类似普通超链接的LinkBut​​ton是不好的做法,甚至更糟糕的做法是在POST返回发生后进行302重定向。

  1. For one thing it breaks the browser interaction which you have already found.
  2. 首先,它打破了您已经找到的浏览器交互。

  3. But more importantly it breaks search engine indexing of your site, if you have an external site.
  4. 但更重要的是,如果您有外部网站,它会破坏您网站的搜索引擎索引。

Also you still can do some pre-processing on an actual hyperlink, but you just do it in a different manor. If you tell us what you are doing maybe we can help find a better way.

您还可以对实际超链接进行一些预处理,但您只需在不同的庄园中进行预处理。如果你告诉我们你在做什么,我们可以帮助找到更好的方法。

#2


You could use a HyperLink to some intermediate page and pass some querystring parameters. And then do your redirect in the pageload of the intermediate page. That way you could still open up the links in a new tab or window.

您可以将HyperLink用于某个中间页面并传递一些查询字符串参数。然后在中间页面的页面加载中进行重定向。这样你仍然可以在新的标签页或窗口中打开链接。

#3


Why not just pass querystrings with the data you need? Posting back, then redirecting not only kills performance (2x as many round trips for the client), but it reeks of bad design.

为什么不用你需要的数据传递查询字符串?发回,然后重定向不仅会导致性能下降(客户端往返次数的2倍),但它的设计很糟糕。