' Codes in code behind:
Me.WebImageButton1.ClientSideEvents.Click = "clickButton1"
Me.WebImageButton1.ClientSideEvents.Paint = "paintButton1"
Me.WebImageButton1.ClientSideEvents.KeyDown = "keyButton1"
' Note: if codes above are written within aspx, then it reduces the size of hidden ViewState passed to client
' Below are codes in aspx (or any other script file loaded to client)
<script language="javascript">
// function called before WebImageButton1 gets the click event
function clickButton1(oButton, oEvent)
{
// if click was triggered by the Space key, then cancel click
if(oEvent.action == "1")
oEvent.cancel = true;
// if click was triggered by the AccessKey, then cancel automatic post back to server
if(oEvent.action == "3")
oEvent.cancelPostBack = true;
}
// function called while painting of WebImageButton1
function paintButton1(oButton, oEvent)
{
// get reference to html element that renders text of button
var span = oButton.getElementAt(3);
var border = "0";
// draw red solid border around text when button in pressed state
if(oButton.getState() == 4)
border = "1px solid red";
span.style.border = border;
}
// function called when WebImageButton1 gets the keydown event
function keyButton1(oButton, oEvent)
{
// if the Escape key was pressed, then trigger post back to server
if(oEvent.event.keyCode == 27)
oEvent.needPostBack = true;
}
</script>