[英]href of anchor tag inside listview not fired
I have a listview which contain an tag inside it, also it contain an href, but the href is not working. 我有一个列表视图,其中包含一个标签,它也包含一个href,但是href无法正常工作。 Here is the code 这是代码
<asp:ListView ID="listsearch" runat="server" ItemPlaceholderID="itemsearch">
<LayoutTemplate>
<ul class="ada"><asp:PlaceHolder ID="itemsearch" runat="server"/></ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%# String.Format("https://www.google.co.in") %> ' Text="Ssdsd"/>
</li>
</ItemTemplate>
</asp:ListView>
HTML output: HTML输出:
<a id="ctl00_ContentPlaceHolder1_listsearch_ctrl0_LinkButton1" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$listsearch$ctrl0$LinkButton1", "", false, "", "google.co.in";, false, true))' style="border-width: 1px;">Ssdsd</a>
<asp:LinkButton>
control is intended for simulate the behaviour of an <asp:button>
but in hyperlink taste. <asp:LinkButton>
控件用于模拟<asp:button>
的行为,但具有超链接味道。 If you do not need server processing on click event better use <asp:hyperlink>
or simply non-server html <a>
tag: 如果不需要在单击事件上进行服务器处理,最好使用<asp:hyperlink>
或简单地使用非服务器html <a>
标记:
I guess you've a property like Url in the DataSource passed to the ListView, so you replace your LinkButton for something like that: 我猜您在传递给ListView的DataSource中有一个类似Url的属性,因此您将LinkButton替换为类似的内容:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("myUrl") %>'
Target="_blank"><%# Eval("myUrl") %></asp:HyperLink>
Or better: 或更好:
<a href="<%# Eval("MyUrl") %>" target="_blank"><%# Eval("MyUrl") %></a>
And also opens the url in a new tab! 并在新标签页中打开网址!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.