If you want to use javascript code then here you go:-
function CountChar(sender) {
var str = sender.value;
var res = str.split("a").length - 1;
document.getElementById("lblText").innerHTML = res;
}
Now onkeydown property of TextBox call the function:-
<asp:TextBox ID="txtText" runat="server" onkeydown="CountChar(this)" />
Good luck