2017-03-06 67 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>