I have a listview which contain an tag inside it, also it contain an href, but the href is not working. 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:
<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. If you do not need server processing on click event better use <asp:hyperlink>
or simply non-server html <a>
tag:
I guess you've a property like Url in the DataSource passed to the ListView, so you replace your LinkButton for something like that:
<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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.