c# - Add serverside onclick event to programmatically created div -
[coding in asp.net]
i creating page divs created in code behind content loaded sql database.
i have div contains number of votes users have given current data , when click on want number of votes go one. require executing query , reloading update panel. (i not want postback)
how can create onclick event programmatically created div calls c# method (with query)?
after bit of digging found solution works quite , easy implement.
i had create asp:button programmatically event:
button divbutton = new button(); divbutton.attributes["style"] = "display:none;"; divbutton.id = "divbtn_" + id; divbutton.text = id; divbutton.click += divbutton_click;
when create clickable div following:
div.attributes.add("onclick", "return divclick(" + sqlid + ");");
this calls following javascript:
<script> function divclick(id) { var button = document.getelementbyid('divbtn_' + id); button.click(); return false; } </script>
which calls button executes sql query using id.
Comments
Post a Comment