The issue is that editing the text inputs value as someone types will reset the caret (cursor) position to after the new text.
You need to A: Get where the caret is before changing the text and B: Set the caret after changing the text:
function A(element){
return element.selectionStart;
}
function B(element, caret){
element.setSelectionRange(caret,caret);
}
function toUpper(element){
var caret = A(this);
this.value = this.value.ToUpperCase();
B(this,caret);
}
Oh and pass the whole element (you don't HAVE to though):
<asp:textbox id="txtPatientname" runat="server" onkeyup="ToUpper(this)" cssclass="txtbox" font-names="Calibri" font-size="Medium" height="20px" maxlength="50" tabindex="6" tooltip="Patient name" width="175px" xmlns:asp="#unknown"></asp:textbox>
Hope that helps :)