简体   繁体   English

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

[英]Why is my Aspx page rendering different HTML in FireFox and IE

I have come across a problem where, my asp.net code is being rendered differently on Firefox and IE. 我遇到过一个问题,我的asp.net代码在Firefox和IE上呈现的方式不同。 When I say differently, I mean, A linkButton in IE renders as anchor tags. 当我说的不同时,我的意思是,IE中的linkBut​​ton呈现为锚标签。 On Firefox however, it renders as a span 然而,在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. 尽管可见,但其他一些控件根本不会渲染。 替代文字 替代文字

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. 更新:好的,这是一个AJAX页面,gridview位于更新面板内,它响应LinkBut​​ton的OnCommand事件。 The code obviously compiles, and it runs fine on IE. 代码显然编译,它在IE上运行良好。

I have checked the Page Source on firefox and it is the same as the image. 我在firefox上检查了Page Source,它和图像一样。 There was a good point made about the lack of ID on the containing DIV tag. 关于包含DIV标签的ID缺乏,有一个很好的观点。 Does embedded script cause problems for FireFox? 嵌入式脚本是否会导致FireFox出现问题? What about id's beginning with numbers? 那个id从数字开始怎么样?

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 http://aspnetresources.com/blog/adaptive_rendering.aspx

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

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,因此它们不应该影响这里的事情。

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. Jay S非常正确地指出我应该确保我正在查看正确的代码实例。 Some of the links on the local version are pointing to the Dev version on the Dev Server. 本地版本上的某些链接指向Dev Server上的Dev版本。 It is not up to date and actually has old code running there from before the product names were converted to links. 它不是最新的,并且在将产品名称转换为链接之前实际上已经运行了旧代码。

Apologies for wasting the collective brain energy and thank you all for your replies. 为浪费集体大脑能量而道歉并感谢大家的回复。

According to Microsof the LinkButton "Displays a hyperlink-style button control on a Web page.". 根据Microsof的LinkBut​​ton“在网页上显示超链接式按钮控件。”。 As such I would not expect adaptive rendering to change this from a HyperLink to a span. 因此,我不希望自适应渲染将其从HyperLink更改为跨度。 I have never seen this behaviour. 我从未见过这种行为。

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? 是否有任何DHTML或JS加载在页面发布后更改HTML?
  2. Are there any assemblies / server controls installed that override the default behaviour a link button? 是否安装了任何程序集/服务器控件,以覆盖链接按钮的默认行为?
  3. 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. 尝试使用绑定链接按钮的空白soloution并尝试重现,然后通过向项目添加asseblies和控件来确定导致问题的原因。

Unfortunatly there is not enough information in your question from your code, and screen shots to give you a definative answer at this stage. 遗憾的是,您的问题中没有足够的信息来自您的代码和屏幕截图,以便在此阶段给您一个明确的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM