为什么我的Aspx页面在FireFox和IE中呈现不同的HTML

时间:2022-03-30 22:47:08

I have come across a problem where, my asp.net code is being rendered differently on Firefox and IE. When I say differently, I mean, A linkButton in IE renders as anchor tags. On Firefox however, it renders as a span

我遇到过一个问题,我的asp.net代码在Firefox和IE上呈现的方式不同。当我说的不同时,我的意思是,IE中的linkBut​​ton呈现为锚标签。但是在Firefox上,它呈现为跨度

code example

<ItemTemplate>
   <div id="<%#Eval("Id","{0}") %>">
     <asp:LinkButton ID="ProductName" runat="server" CommandName="Listing" 
       CommandArgument='<%# Bind("Id") %>' Text='<%# Bind("Name") %>PostBackUrl=""></asp:LinkButton>
     <asp:Label ID="lbl_pricePerUnit" runat="server" Text="" />
   </div>
</ItemTemplate>

Some other controls aren't rendered at all, though visible.alt text http://i39.tinypic.com/i739k4.jpgalt text http://i40.tinypic.com/154dee1.jpg

其他一些控件根本没有渲染,尽管可见。盐文本http://i39.tinypic.com/i739k4.jpgalt文本http://i40.tinypic.com/154dee1.jpg

I have no idea what's going on here and I have never seen this happen before. I am using the latest versions of the browsers and I have asp.net 3.5 and VS2008

我不知道这里发生了什么,我以前从未见过这种情况。我使用的是最新版本的浏览器,我有asp.net 3.5和VS2008

UPDATE: Ok this is an AJAX page, the gridview is inside an update panel which reacts to the OnCommand event of the LinkButton. The code obviously compiles, and it runs fine on IE.

更新:好的,这是一个AJAX页面,gridview位于一个更新面板内,它响应LinkBut​​ton的OnCommand事件。代码显然编译,它在IE上运行良好。

I have checked the Page Source on firefox and it is the same as the image. There was a good point made about the lack of ID on the containing DIV tag. Does embedded script cause problems for FireFox? What about id's beginning with numbers?

我在firefox上检查了Page Source,它和图像一样。关于包含DIV标签的ID缺乏,有一个很好的观点。嵌入式脚本是否会导致FireFox出现问题?那个id从数字开始怎么样?

5 个解决方案

#1


Surely this is caused by adaptive rendering, where ASP.Net emits html tailored for the browser?

当然这是由自适应渲染引起的,其中ASP.Net发布为浏览器量身定制的html?

http://aspnetresources.com/blog/adaptive_rendering.aspx

#2


In your code sample, the asp:LinkButton tag is incorrectly formed - there is a missing "<".

在您的代码示例中,asp:LinkBut​​ton标记格式不正确 - 缺少“<”。

#3


It looks like there are some other problems with your templates.

您的模板看起来还有其他一些问题。

As Chris states in a comment "Possibly if the link has no href?"

正如克里斯在评论中所说:“可能链接没有href吗?”

Looking at the html that has been generated in Firefox, there's also no ID on the containing div - while there is in IE.

看看在Firefox中生成的html,在包含的div上也没有ID - 而在IE中也是如此。

Bear in mind that using Firebug to look at the source in Firefox, and actually looking at the source (right-click|View Page Source) are two different things - Firebug will display the source as parsed and processed by the browser, with any additions that JavaScript or the Browser engine have added/changed - Using the View Page Source will show you the actual source returned from the server before any processing happened - is that code correct/the same?

请记住,使用Firebug查看Firefox中的源代码,并实际查看源代码(右键单击|查看页面源代码)是两回事 - Firebug将显示源代码由浏览器解析和处理,添加任何内容JavaScript或浏览器引擎已添加/更改 - 使用View Page Source将显示在发生任何处理之前从服务器返回的实际源 - 该代码是否正确/相同?

BrowserCaps used to make a right mess of all sorts of controls in a 1.x world - however they were updated to support Firefox etc with ASP.NET 2.0, so they shouldn't be affecting things here.

BrowserCaps用于在1.x世界中制作各种各样的控件 - 但是它们已经更新为支持Firefox等与ASP.NET 2.0,因此它们不应该影响这里的事情。

#4


I am very emabarrased to admit that I have made the most absent minded of blunders

我非常痴迷于承认我已经做出了最缺乏思想的错误

Jay S very rightly pointed out that I should make sure I'm looking at the correct instance of the code. Some of the links on the local version are pointing to the Dev version on the Dev Server. It is not up to date and actually has old code running there from before the product names were converted to links.

Jay S非常正确地指出我应该确保我正在查看正确的代码实例。本地版本上的某些链接指向Dev Server上的Dev版本。它不是最新的,实际上在产品名称转换为链接之前就已经运行了旧代码。

Apologies for wasting the collective brain energy and thank you all for your replies.

为浪费集体大脑能量而道歉并感谢大家的回复。

#5


According to Microsof the LinkButton "Displays a hyperlink-style button control on a Web page.". As such I would not expect adaptive rendering to change this from a HyperLink to a span. I have never seen this behaviour.

根据Microsof的LinkBut​​ton“在网页上显示超链接式按钮控件。”。因此,我不希望自适应渲染将其从HyperLink更改为跨度。我从未见过这种行为。

If this is truly what is happening then you may want to check a couple of thigs:

如果这确实是发生了什么,那么你可能想要检查几个thigs:

  1. Are there any DHTML or JS loading that changes the HTML after the page has published?
  2. 是否有任何DHTML或JS加载在页面发布后更改HTML?

  3. Are there any assemblies / server controls installed that override the default behaviour a link button?
  4. 是否安装了任何程序集/服务器控件,以覆盖链接按钮的默认行为?

  5. Try a blank soloution with the bound link button and try to reproduce, then back track by adding asseblies & controls to the project to determine what is causing the issue.
  6. 尝试使用绑定链接按钮的空白解决方案并尝试重现,然后通过向项目添加组件和控件来确定导致问题的原因。

Unfortunatly there is not enough information in your question from your code, and screen shots to give you a definative answer at this stage.

不幸的是,您的问题中没有足够的信息来自您的代码和屏幕截图,以便在此阶段给您一个明确的答案。

#1


Surely this is caused by adaptive rendering, where ASP.Net emits html tailored for the browser?

当然这是由自适应渲染引起的,其中ASP.Net发布为浏览器量身定制的html?

http://aspnetresources.com/blog/adaptive_rendering.aspx

#2


In your code sample, the asp:LinkButton tag is incorrectly formed - there is a missing "<".

在您的代码示例中,asp:LinkBut​​ton标记格式不正确 - 缺少“<”。

#3


It looks like there are some other problems with your templates.

您的模板看起来还有其他一些问题。

As Chris states in a comment "Possibly if the link has no href?"

正如克里斯在评论中所说:“可能链接没有href吗?”

Looking at the html that has been generated in Firefox, there's also no ID on the containing div - while there is in IE.

看看在Firefox中生成的html,在包含的div上也没有ID - 而在IE中也是如此。

Bear in mind that using Firebug to look at the source in Firefox, and actually looking at the source (right-click|View Page Source) are two different things - Firebug will display the source as parsed and processed by the browser, with any additions that JavaScript or the Browser engine have added/changed - Using the View Page Source will show you the actual source returned from the server before any processing happened - is that code correct/the same?

请记住,使用Firebug查看Firefox中的源代码,并实际查看源代码(右键单击|查看页面源代码)是两回事 - Firebug将显示源代码由浏览器解析和处理,添加任何内容JavaScript或浏览器引擎已添加/更改 - 使用View Page Source将显示在发生任何处理之前从服务器返回的实际源 - 该代码是否正确/相同?

BrowserCaps used to make a right mess of all sorts of controls in a 1.x world - however they were updated to support Firefox etc with ASP.NET 2.0, so they shouldn't be affecting things here.

BrowserCaps用于在1.x世界中制作各种各样的控件 - 但是它们已经更新为支持Firefox等与ASP.NET 2.0,因此它们不应该影响这里的事情。

#4


I am very emabarrased to admit that I have made the most absent minded of blunders

我非常痴迷于承认我已经做出了最缺乏思想的错误

Jay S very rightly pointed out that I should make sure I'm looking at the correct instance of the code. Some of the links on the local version are pointing to the Dev version on the Dev Server. It is not up to date and actually has old code running there from before the product names were converted to links.

Jay S非常正确地指出我应该确保我正在查看正确的代码实例。本地版本上的某些链接指向Dev Server上的Dev版本。它不是最新的,实际上在产品名称转换为链接之前就已经运行了旧代码。

Apologies for wasting the collective brain energy and thank you all for your replies.

为浪费集体大脑能量而道歉并感谢大家的回复。

#5


According to Microsof the LinkButton "Displays a hyperlink-style button control on a Web page.". As such I would not expect adaptive rendering to change this from a HyperLink to a span. I have never seen this behaviour.

根据Microsof的LinkBut​​ton“在网页上显示超链接式按钮控件。”。因此,我不希望自适应渲染将其从HyperLink更改为跨度。我从未见过这种行为。

If this is truly what is happening then you may want to check a couple of thigs:

如果这确实是发生了什么,那么你可能想要检查几个thigs:

  1. Are there any DHTML or JS loading that changes the HTML after the page has published?
  2. 是否有任何DHTML或JS加载在页面发布后更改HTML?

  3. Are there any assemblies / server controls installed that override the default behaviour a link button?
  4. 是否安装了任何程序集/服务器控件,以覆盖链接按钮的默认行为?

  5. Try a blank soloution with the bound link button and try to reproduce, then back track by adding asseblies & controls to the project to determine what is causing the issue.
  6. 尝试使用绑定链接按钮的空白解决方案并尝试重现,然后通过向项目添加组件和控件来确定导致问题的原因。

Unfortunatly there is not enough information in your question from your code, and screen shots to give you a definative answer at this stage.

不幸的是,您的问题中没有足够的信息来自您的代码和屏幕截图,以便在此阶段给您一个明确的答案。