You can make a asp.net object button or image button, and add the attribute onClientClick
So you make the button, press F4, in the property onClientClick enter "hi(); return false;" without the double quotes.
return false cancels the button postback event. You can do return hi();
and if hi returns true, the postback event fires, and if hi() returns false, the postback is canceled.
Just remember to register your java script file first.
[EDIT]
To fix your code above, you need to create the element correctly first for it to work. Don't use setAttribute, JavaScript has everything you need to build the element.
var inputObj = document.createElement ("input");
inputObj.type = "button"
<head>
<script type="text/javascript">
function AddButton () {
var button = document.createElement ("input");
button.type = "button";
button.value = "Create a new button";
button.onclick = AddButton;
var container = document.getElementById ("buttonContainer");
container.appendChild (button);
}
</script>
</head>
<body onload="AddButton ()">
<div id="buttonContainer"></div>
</body>
http://help.dottoro.com/ljxhibki.php[
^]