You can pass object as parameter to generalize function
<asp:TextBox ID="txtName" onkeypress="showContent(event,this)" ClientIDMode="Static" runat="server">
<label id="lblPrview" ></label>
<script type="text/javascript">
function showContent(e,object) {
var recentChar = String.fromCharCode(e.which);
var completetext = object.value + recentChar;
// assign value using js
document.getElementById('lblPrview').innerHTML = completetext;
}
</script>