2016-05-24 25 views
0

有沒有方法將點擊事件添加到在ListView中呈現的超鏈接標記中? 基本上,我有一個HyperLink標記,可以動態生成一個鏈接,當用戶點擊它時打開一個新標籤頁。同時,當用戶點擊它時,我想發佈文本或使文本標籤可見。示例代碼如下:將點擊事件添加到在ListView中顯示的超鏈接ASP.NET ASP.NET

<asp:ListView ...> 
    <ItemTemplate> 
    <asp:Label ID="Msg" Text="*You have already accessed this link*" runat="server" Visible="false"/> 
    <asp:HyperLink ID="label1" NavigatUrl='<%#Eval("Link")%>'Target="_blink" text="Click Link" runat="server"></asp:HyperLink> 
    <//ItemTemplate> 
</asp:ListView> 
+1

這可能是有益的:http://stackoverflow.com/questions/20098257/asp-net-listview-click-row-perform-action .. 。下次搜索......關於它的很多話題。 –

+0

這不起作用。他正在用JavaScript重定向頁面,而不是保持在同一頁面上。另外,他沒有使用超鏈接標籤從頁面移動。我不想從頁面移動,只需打開一個新標籤。您無法使用JavaScript打開新選項卡,因爲瀏覽器阻止彈出窗口。 – Kluong

+1

我發現1000個答案之一。先粘貼。但也許你做了搜索,這是一些其他的情況......然後對那個評論感到抱歉。 –

回答

0

您可以使用QueryString。添加鏈接與查詢參數就可以了,然後 -

If IsPostBack=True then 'Check if the page is reloading [Because when you clik on the link with the same link, it will reload the page] 
'Considering the QueryString will be like - "yourdomain/default.aspx?item=1" 
'Check for QueryString 
Dim s_ItemId As String = Request.QueryString("item") 

if s_ItemId<>"" then 
'Do whatever you want  
End If