我的代码后面有一个属性。我的代码设置如下:
Protected url As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.DataBind()
url = string.Format("'page.html?param1=paramValue1¶m2={0}'", paramValue2)
If Page.IsPostBack = False Then
'some legacy code
End If
End Sub
我希望将此url作为javascript函数的参数传递,该函数在单击表行项时被调用:
<tr onmouseover="m_over()" onmouseout="m_out()" id="Link" runat="server" onclick="m_click(<%# url %>)">
<td class="menu-item">
Link
</td>
</tr>
在运行时,这就是我的页面源:
<tr id="Link" onmouseover="m_over()" onmouseout="m_out()" onclick="m_click(<%# url %>)">
<td class="menu-item">
Link
</td>
</tr>
我做错了什么?
答案 0 :(得分:0)
使用<%= ... %>
语法代替<%# ... %>
并将onclick=...
插入其中:
<tr id="LinkSiteStaff" onmouseover="m_over()" onmouseout="m_out()" <%= "onclick=m_click(" + url + ")" %>>