Capital letters in a textbox

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
Hello,

I have a question. Is it possible that when someone types in a textbox that the letters that are being typed ared immediatly capital letters? I know you can use OntextChanged and autopostback and then do a ToUpper but the autopostback is very annoying. So i want to know if there's a way to upper them without an autopostback.

Thx

Neske
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,

Try out this ..............

<script type="text/javascript">

function UpperCase(e)
{
var key;
var keychar;
var reg;
if(window.event)
{
// for IE, e.keyCode or window.event.keyCode can be used
key = e.keyCode;
}
else if(e.which)
{
// netscape
key = e.which;
}
else {
// no event, so pass through
return true;
}
key = String.fromCharCode(key).toUpperCase().charCodeAt(0)
window.event.keyCode = key
}
</Script>


In Page load event add................

txtName.Attributes("onkeypress") = "javascript:return " & _
" UpperCase(event);"


I hope this will help u................

Regards,
Ritesh
 

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
Hi,

I've tried it but it doesn't do anything. I word in vb.net, and i placed what you gave me in a string and then called it in my pageload. But it doesn't really do something. This is how i changed it:

Me.TextnaamZoek.Attributes.Add("onkeypress", "return UpperCase(event);")

Private Sub grootte()

Dim js As String = "<script language=JavaScript>Function UpperCase(ByVal e){var key;var keychar;var reg;If (window.event) Then{key = e.keyCode;}ElseIf (e.which) Then{key = e.which; }else {return true;}key = String.fromCharCode(key).toUpperCase().charCodeAt(0)window.event.keyCode = key}</script>"

'RegisterStartupScript("UpperCase", js)
RegisterClientScriptBlock("UpperCase", js)
End Sub

I also tried with first calling grootte and then do the attributes add. But when i type something in the textbox the letters are small.
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,
Simple Paste the Script in ur aspx........it will work ..................
Let me the Result..............

Reagrds,
Ritesh
 

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
Hi,

Did what you said just pasted it in the aspx. And called it in the page load. But still it doesn't do anything

Neske
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,
If possible can u pls. paste ur aspx and page load code??


Here is what i did..............

<HEAD>
<title>HTSDossierType</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
function UpperCase(e)
{
var key;
var keychar;
var reg;
if(window.event)
{
// for IE, e.keyCode or window.event.keyCode can be used
key = e.keyCode;
}
else if(e.which)
{
// netscape
key = e.which;
}
else {
// no event, so pass through
return true;
}
key = String.fromCharCode(key).toUpperCase().charCodeAt(0)
window.event.keyCode = key
}

</script>
</HEAD>


and...............

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtCode.Attributes("onkeypress") = "javascript:return " & _
" UpperCase(event);"

End sub
 

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
Hi Just have the same thing but here it is.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.test.Attributes("onkeypress") = "javascript:return " & " UpperCase(event);"
End Sub

<head>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">

<script type="text/javascript">

function UpperCase(e)
{
var key;
var keychar;
var reg;
if(window.event)
// for IE, e.keyCode or window.event.keyCode can be used
key = e.keyCode;
}
else if(e.which)
{
// netscape
key = e.which;
}
else
{
// no event, so pass through
return true;
}
key = String.fromCharCode(key).toUpperCase().charCodeAt( 0) window.event.keyCode = key
}
</Script>
</head>

<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="test" Runat="server"></asp:TextBox>
</form>
</body>
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi,
Here is code with little modification.............

<HEAD>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script type="text/javascript">
function UpperCase(e)
{
var key;
var keychar;
var reg;
if(window.event)
{
// for IE, e.keyCode or window.event.keyCode can be used
key = e.keyCode;
}
else if(e.which)
{
// netscape
key = e.which;
}
else {
// no event, so pass through
return true;
}
key = String.fromCharCode(key).toUpperCase().charCodeAt(0)
window.event.keyCode = key
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="test" Runat="server"></asp:TextBox>
</form>
</body>


I hopw this will work fine...............

Ritesh
 

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
Hi,

Ok that works fine. Thank you very much. But what did you just change? I looked at the code but i didn't seem to find a difference.

Neske
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Great.................finally it's work out............

nothing new just forgot............"{" after if(window.event)

Regards,
Ritesh
 

Neske

Member
Joined
Mar 1, 2005
Messages
17
Programming Experience
Beginner
ah ok. Well thank you again :). It's super.
 

k89mmk

Member
Joined
Jun 7, 2005
Messages
6
Location
n/a
Programming Experience
3-5
There is an easier way!!!

Add Style="text-transform: uppercase;" to your textbox.

VB.NET:
 <asp:TextBox id="test" Style="text-transform: uppercase;" Runat="server"></asp:TextBox>
Thats it! Thats all you need!
 

hugolterrible

New member
Joined
Jan 4, 2006
Messages
1
Location
Mexico City
Programming Experience
5-10
Very Good

k89mmk said:
There is an easier way!!!

Add Style="text-transform: uppercase;" to your textbox.

VB.NET:
 <asp:TextBox id="test" Style="text-transform: uppercase;" Runat="server"></asp:TextBox>
Thats it! Thats all you need!
that is very good
 
Top Bottom