IE9 Javascript未定义错误
我在IE9中遇到了一个javascript错误,我在Chrome或FF中没有遇到这个错误,我想不出一个好方法来解决它。代码在兼容模式下工作 在示例代码中,我有一个自定义用户控件,它由几个基本控件和一个AJAX modelpopupextender组成。listview填充一些产品,我附加了一个onclick事件onitemdatabound,它填充标签并关闭listview项的每个htmlrow的modelpopup IE9找不到Button2,无法完成javascript函数。当前版本的Chrome和FF按预期运行。有什么我遗漏的吗 资料来源:IE9 Javascript未定义错误,javascript,asp.net,internet-explorer,Javascript,Asp.net,Internet Explorer,我在IE9中遇到了一个javascript错误,我在Chrome或FF中没有遇到这个错误,我想不出一个好方法来解决它。代码在兼容模式下工作 在示例代码中,我有一个自定义用户控件,它由几个基本控件和一个AJAX modelpopupextender组成。listview填充一些产品,我附加了一个onclick事件onitemdatabound,它填充标签并关闭listview项的每个htmlrow的modelpopup IE9找不到Button2,无法完成javascript函数。当前版本的Chr
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SelectProduct.ascx.vb" Inherits="SelectProduct" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
</style>
<asp:Panel ID="Panel1" runat="server" BackColor="Wheat">
<table style="padding:5px;">
<tr>
<td style="width:40px;"> </td>
<td style="width:400px;text-align:center;">
<b style="font-size:12pt;color:#155184;">Select a Product</b>
</td>
<td style="width:40px;text-align:right;">
<asp:Button ID="Button2" runat="server" Text="X" CausesValidation="false" />
</td>
</tr>
</table>
<asp:Panel ID="Panel2" runat="server" Height="500" ScrollBars="Auto" BackColor="White">
<table style="padding:5px;">
<tr>
<td colspan="3">
<asp:ListView ID="ListView1" runat="server" DataSourceID="sqlProducts" DataKeyNames="productid, productname">
<LayoutTemplate>
<table cellpadding="4" cellspacing="0" style="width:480px;border:solid 1px #cccccc;" rules="all">
<tr>
<th style="width:100px;">ID</th>
<th style="width:280px;">Name</th>
<th style="width:100px;">Price</th>
</tr>
<tr id="itemPlaceHolder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="selectedProduct" runat="server" style="cursor:pointer;">
<td style="width:100px;text-align:center;">
<asp:Label ID="lblID" runat="server" Text='<%# Eval("productid") %>' />
</td>
<td style="width:280px;text-align:center;">
<asp:Label ID="lblName" runat="server" Text='<%# Eval("productname") %>' />
</td>
<td style="width:100px;padding-left:4px;">
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("unitprice") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="sqlProducts" runat="server"
ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="select productid, productname, unitprice from products">
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Panel>
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Select a Product..." CausesValidation="false" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="Panel1" TargetControlID="Button1" CancelControlID="Button2">
</asp:ModalPopupExtender>
生成的HTML:
<div>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
</style>
<div id="SelectProduct1_Panel1" style="background-color: Wheat;">
<table style="padding: 5px;">
<tr>
<td style="width: 40px;">
</td>
<td style="width: 400px; text-align: center;">
<b style="font-size: 12pt; color: #155184;">Select a Product</b>
</td>
<td style="width: 40px; text-align: right;">
<input type="submit" name="SelectProduct1$Button2" value="X" id="SelectProduct1_Button2" />
</td>
</tr>
</table>
<div id="SelectProduct1_Panel2" style="background-color: White; height: 500px; overflow: auto;">
<table style="padding: 5px;">
<tr>
<td colspan="3">
<table cellpadding="4" cellspacing="0" style="width: 480px; border: solid 1px #cccccc;"
rules="all">
<tr>
<th style="width: 100px;">
ID
</th>
<th style="width: 280px;">
Name
</th>
<th style="width: 100px;">
Price
</th>
</tr>
<tr id="SelectProduct1_ListView1_ctrl0_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Chai";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl0_lblID">1</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl0_lblName">Chai</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl0_lblPrice">18.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl1_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Chang";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl1_lblID">2</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl1_lblName">Chang</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl1_lblPrice">19.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl69_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Outback Lager";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl69_lblID">70</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl69_lblName">Outback Lager</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl69_lblPrice">15.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl70_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Flotemysost";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl70_lblID">71</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl70_lblName">Flotemysost</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl70_lblPrice">21.5000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl71_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Mozzarella di Giovanni";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl71_lblID">72</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl71_lblName">Mozzarella di Giovanni</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl71_lblPrice">34.8000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl72_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Röd Kaviar";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl72_lblID">73</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl72_lblName">Röd Kaviar</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl72_lblPrice">15.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl73_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Longlife Tofu";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl73_lblID">74</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl73_lblName">Longlife Tofu</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl73_lblPrice">10.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl74_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Rhönbräu Klosterbier";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl74_lblID">75</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl74_lblName">Rhönbräu Klosterbier</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl74_lblPrice">7.7500</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl75_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Lakkalikööri";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl75_lblID">76</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl75_lblName">Lakkalikööri</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl75_lblPrice">18.0000</span>
</td>
</tr>
<tr id="SelectProduct1_ListView1_ctrl76_selectedProduct" style="cursor: pointer;"
onclick="SelectProduct1_Label1.innerText="Original Frankfurter grüne Soße";SelectProduct1_Button2.click();">
<td style="width: 100px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl76_lblID">77</span>
</td>
<td style="width: 280px; text-align: center;">
<span id="SelectProduct1_ListView1_ctrl76_lblName">Original Frankfurter grüne Soße</span>
</td>
<td style="width: 100px; padding-left: 4px;">
<span id="SelectProduct1_ListView1_ctrl76_lblPrice">13.0000</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
<input type="submit" name="SelectProduct1$Button1" value="Select a Product..." id="SelectProduct1_Button1" />
<span id="SelectProduct1_Label1"></span>
</div>
唯一的问题是,我要么每页只放置一个此用户控件,要么为每个控件在客户端脚本服务器端注册一个唯一的函数名
至少我让它工作了。您可能想尝试更改:
row.Attributes.Add("onclick", Label1.ClientID + ".innerText=""" + product + """;" + Button2.ClientID + ".click();")
致:
您可能希望尝试更改:
row.Attributes.Add("onclick", Label1.ClientID + ".innerText=""" + product + """;" + Button2.ClientID + ".click();")
致:
我有类似的问题与自定义网络控制。我把这个问题追溯到ASP.NET 简言之,ASP.NET不知道IE9浏览器ID,因此返回默认的兼容性标志,包括EcmaScriptVersion(请参阅),它关闭基类中的脚本生成 我真的希望他们能在IE9发布后更新.net,但没有 这些是我用来规避这种烦恼的(独立)解决方案:
browserCaps
部分添加到web.config
(这将有效地为所有浏览器打开cookies和javascript):
浏览器=未知
cookies=true
javascript=true
ecmascriptversion=1.0
我有类似的问题与自定义网络控制。我把这个问题追溯到ASP.NET 简言之,ASP.NET不知道IE9浏览器ID,因此返回默认的兼容性标志,包括EcmaScriptVersion(请参阅),它关闭基类中的脚本生成 我真的希望他们能在IE9发布后更新.net,但没有 这些是我用来规避这种烦恼的(独立)解决方案:
browserCaps
部分添加到web.config
(这将有效地为所有浏览器打开cookies和javascript):
浏览器=未知
cookies=true
javascript=true
ecmascriptversion=1.0
为FF/Chrome生成了什么HTML?asp.net猜测您使用的浏览器,并调整它生成的HTML。您可能需要在标准模式下更新IE9的浏览器功能文件。FF/Chrome会生成什么HTML?asp.net猜测您使用的浏览器,并调整它生成的HTML。您可能需要在标准模式下更新IE9的浏览器功能文件。我不能保证这是解决此特定问题的答案,但我遇到过一些类似的错误,这些错误都是通过这种方式解决的。GetElementByID现在是我的标准方法。我确实尝试过,但它没有解决这个问题。IE9仍然找不到Button2。我不能保证这就是这个特定问题的答案,但我也遇到过一些类似的错误,它们都是通过这种方式解决的。GetElementByID现在是我的标准方法。我确实尝试过,但它没有解决这个问题。IE9仍然找不到按钮2。
Dim row As HtmlTableRow = CType(e.Item.FindControl("selectedProduct"), HtmlTableRow)
Dim lblName As Label = e.Item.FindControl("lblName")
Dim product As String = ListView1.DataKeys(CType(e.Item, ListViewDataItem).DataItemIndex).Values(1).ToString()
Dim id As String = ListView1.DataKeys(CType(e.Item, ListViewDataItem).DataItemIndex).Values(0).ToString()
row.Attributes.Add("onclick", "selectProduct(" + lblName.ClientID + ".innerText);")
row.Attributes.Add("onclick", Label1.ClientID + ".innerText=""" + product + """;" + Button2.ClientID + ".click();")
row.Attributes.Add("onclick", Label1.ClientID + ".innerText=""" + product + """;document.getElementById(""" + Button2.ClientID + """).click();")
<configuration>
<system.web>
<browserCaps>
<use var="HTTP_USER_AGENT" />
browser=Unknown
cookies=true
javascript=true
ecmascriptversion=1.0
</browserCaps>
</system.web>
</configuration>