Call code behind by clicking on a table row
When the user clicks on a row TR in a table. I would like to call the code behind function ViewButtonPressed_Click(MapId)...
The plan was to: upon clicking a row, fires a JS function, which calls a button click for asp.net button which calls ViewButtonPressed_Click(MapId).
I have done this by calling a JS function doPostBack(id) when the row is clicked. This works as I was able to fire an alert. The problem is happening when I am trying to call the button click from JS
<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"/>
When I run the page I am getting
The name 'btn_ViewMap' does not exist in the current context: document.getElementById('<%=btn_ViewMap.ClientID%>').click();
I have looked at a previous q:How to call a asp:Button OnClick event using JavaScript? but to no avail....any ideas?
链接地址: http://www.djcxy.com/p/31000.html上一篇: 将按钮可见性设置为后面的错误代码
下一篇: 通过点击表格行来调用代码