当用户点击表格中的行TR时。我想调用函数ViewButtonPressed_Click(MapId)后面的代码...
计划是:点击一行后,触发一个JS函数,调用一个按钮点击asp.net按钮调用ViewButtonPressed_Click(MapId)。
我通过在单击行时调用JS函数doPostBack(id)来完成此操作。这是有效的,因为我能够发出警报。当我尝试从JS </ p>调用按钮单击时,问题就出现了
<script type="text/javascript">
function doPostBack(id) {
alert("MAP ID is " + id);
document.getElementById('<%=btn_ViewMap.ClientID%>').click();
//ALSO I WOULD LIKE TO PASS THE MAP_ID to the buttom, which is passed to code behind?
}
</script>
<tr id="Tr2" runat="server" class="itemTableData" onclick='<%#"doPostBack("+Eval("ID")+")" %>'>
<asp:Button ID="btn_ViewMap" runat="server" OnClick="ViewButtonPressed_Click(mapId)" style="display:none"/>
当我运行页面时,我正在
The name 'btn_ViewMap' does not exist in the current context: document.getElementById('<%=btn_ViewMap.ClientID%>').click();
我看过之前的q:How to call a asp:Button OnClick event using JavaScript?,但无济于事....任何想法?