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

发布于 2024-07-12 06:12:27 字数 1126 浏览 7 评论 0原文

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

代码示例

<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>

。其他一些控件虽然可见,但根本不呈现。 替代文字替代文本

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

更新: 好的,这是一个 AJAX 页面,gridview 位于更新面板内,该面板对 LinkBut​​ton 的 OnCommand 事件做出反应。 代码显然可以编译,并且在 IE 上运行良好。

我在firefox上检查了页面源,它​​与图像相同。 关于包含 DIV 标签上缺少 ID 的问题,有一个很好的观点。 嵌入式脚本是否会导致 FireFox 出现问题? id 以数字开头怎么样?

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

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
alt text

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

森林散布 2024-07-19 06:12:27

这肯定是由自适应渲染引起的,ASP.Net 会发出为浏览器量身定制的 html?

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

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

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

何时共饮酒 2024-07-19 06:12:27

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

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

天生の放荡 2024-07-19 06:12:27

您的模板似乎还存在其他一些问题。

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

查看 Firefox 中生成的 html,包含的 div 上也没有 ID - 而 IE 中却有。

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

BrowserCaps 曾经在 1.x 世界中搞乱了各种控件 - 然而它们已更新为支持 Firefox 等与 ASP.NET 2.0,所以它们不应该影响这里的事情。

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

As Chris states in a comment "Possibly if the link has no 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.

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?

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.

凉栀 2024-07-19 06:12:27

我非常尴尬地承认我犯了最心不在焉的错误

Jay S非常正确地指出我应该确保我正在查看正确的代码实例。
本地版本上的一些链接指向开发服务器上的开发版本。 它不是最新的,实际上有在产品名称转换为链接之前运行的旧代码。

抱歉浪费了集体的脑力,感谢大家的回复。

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.

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

总攻大人 2024-07-19 06:12:27

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

如果确实发生了这种情况,那么您可能需要检查以下几点:

  1. 页面发布后是否有任何 DHTML 或 JS 加载会更改 HTML?
  2. 是否安装了任何程序集/服务器控件来覆盖链接按钮的默认行为?
  3. 尝试使用绑定链接按钮的空白解决方案并尝试重现,然后通过添加组件和链接来回溯。 对项目进行控制以确定导致问题的原因。

不幸的是,您的问题中的代码和屏幕截图没有足够的信息,无法在现阶段为您提供明确的答案。

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.

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

  1. Are there any DHTML or JS loading that changes the HTML after the page has published?
  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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文