我写了以下菜单:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="javascript:SetRoadMap();" Text="Road Map" Value="SetRoadMap"/>
<asp:MenuItem NavigateUrl="javascript:SetHybridMap();" Text="Hybrid Map" Value="SetHybridMap" />
<asp:MenuItem NavigateUrl="javascript:SearchAddress(document.getElementById('addressToSearch').text);" Text="Search Address" Value="searchAddress" />
</Items>
<StaticItemTemplate>
<asp:Label runat="server" Height="20px" Text='<%# Eval("Text") %>' />
<asp:TextBox ID="addressToSearch" runat="server" Height="15px" Width="250px" Visible='<%# ((string)Eval("Value") == "searchAddress") %>' />
</StaticItemTemplate>
</asp:Menu>
SearchAddress菜单项的URL似乎无法找到附加到其上的文本框(id'addressToSearch')。
欢迎任何建议。
答案 0 :(得分:0)
我找到了答案:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="javascript:SetRoadMap();" Text="Road Map" Value="SetRoadMap"/>
<asp:MenuItem NavigateUrl="javascript:SetHybridMap();" Text="Hybrid Map" Value="SetHybridMap" />
<asp:MenuItem NavigateUrl="javascript:SearchAddress(document.getElementById('addressToSearch').text);" Text="Search Address" Value="searchAddress" />
</Items>
<StaticItemTemplate>
<asp:Label runat="server" Height="20px" Text='<%# Eval("Text") %>' />
<asp:TextBox ID="addressToSearch" runat="server" ClientIDMode="Static" Height="15px" Width="250px" Visible='<%# ((string)Eval("Value") == "searchAddress") %>' />
</StaticItemTemplate>
</asp:Menu>
我应该添加ClientIDMode属性并查找 Value 而不是 Text 。