2017-03-06 81 views
2

我已經在錨標記中添加了id,我想在我的c#代碼中使用此id來更改類名。如何給id並訪問asp.net html頁面中的錨標籤?

但是,我得到一個解析錯誤 -

<a runat="server" id="btn_status_toggle" 
class="btn btn-success" data-toggle="modal" 
data-target="#myModal" 
onclick="fun(<%# Eval("ID")%>)">Status</a> 

我不知道是什麼問題。

Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

Source Error:

Line 95:
Line 96: &RoleName=<%# Eval("RoleName")%>'>Edit Line 97: )">Status Line 98: Line 99:

Source File: /ShowAdminData.aspx Line: 97

+0

這個錨在哪裏? (例如在一個gridview內?) – Aristos

+0

什麼是樂趣()?是javascript函數還是c#類中的方法 – Usman

回答

1

變化onclick="fun(<%# Eval("ID")%>)"onclick='fun(<%# Eval("ID")%>)'

0

您需要使用:onclick='<%# "fun("+ Eval("ID") + ")" %>'。創建<%# %>塊內的整個onclick值字符串。

<a runat="server" id="btn_status_toggle" class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick='<%# "fun("+ Eval("tocht_id") + ")" %>'>Status</a>