0

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?

Community
  • 1
  • 1
John
  • 3,965
  • 21
  • 77
  • 163
  • You need to create an [MCVE](http://stackoverflow.com/help/mcve). There's a lot of variables here, so you need to narrow down the issue. – mason Mar 25 '15 at 15:42
  • in your stylesheet create a selector .hidden{display: none} and assign it to your button in the CssClass and remove the style attribute. – Kami Mar 25 '15 at 15:56
  • Try `$("button[id$=btn_ViewMap]").click(); ` – Kieran Quinn Mar 25 '15 at 15:56

0 Answers0