Monday, 29 December 2014

AUTO-CAPS ON

Sometime we had a requirement that fields in TextBox should be written in capital letters(BLOCK Letters) no matter caps lock is on or not(Like in bank forms).
For this we can use following simple code. I am providing you two options by using javascript and without javascript.

Without Javascript:  

<asp:TextBox ID="TextBox1" runat="server" class="form-control" 
style= "text-transform:uppercase;"></asp:TextBox>


By Using Javascript:

In .aspx page

<script type="text/javascript">
function toUpper(txt)
{
document.getElementById(txt).value=document.getElementById(txt).value.toUpperCase();
return true; 
}
</script>

TextBox property

<asp:TextBox ID="TextBox1" onkeyup="return toUpper(this.id)" runat="server"></asp:TextBox>





Summary
In this article I try to expose CAPS/Upper Case property of TextBox . I hope after reading this article you will be able to use this trick in your code. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.

No comments:

Post a Comment