Converting to Upper Case

B

Brian Conway

How do I convert a field that is filled in to uppercase within the C3 code?
I see the ToUpper in there, but how do I get the text box to convert this to
upper when you change focus or move to another text box?
 
M

Mattias Sjögren

Brian,

If you mean a Winforms TextBox, wouldn't it be eaiser to just set the
CharacterCasing property to CharacterCasing.Upper, so that all input
is automatically converted to upper case?



Mattias
 
B

Brian Conway

Yes that is what I am trying to do, but can't figure out where or how to get
that in there to get it to work. this is a Web Form so I am thinking that
this is what the problem is.
 
B

Brian Conway

Okay here is the code that I came up with, but it doesn't change the
existing information in the text box on focus change.

string EventName;

EventName = txtEventName.Text;

EventName.ToUpper();

txtEventName.Text = EventName;
 
A

AlexS

Brian

try this:

txtEventName.CharacterCasing=CharacterCasing.Upper;

Note however, that only typed characters will be converted. If you do
something like txtEventName.Text="lowercase string"; contents of text box
will stay in lower case. I think it is small bug in TextBox control, anyway
that's how it is.


HTH
Alex

Brian Conway said:
Okay here is the code that I came up with, but it doesn't change the
existing information in the text box on focus change.

string EventName;

EventName = txtEventName.Text;

EventName.ToUpper();

txtEventName.Text = EventName;
 
B

Brian Conway

I tried that one before but was getting an error of

System.Web.UI.WebControls.TextBox does nto contain a definition for
CharacterCasing

AlexS said:
Brian

try this:

txtEventName.CharacterCasing=CharacterCasing.Upper;

Note however, that only typed characters will be converted. If you do
something like txtEventName.Text="lowercase string"; contents of text box
will stay in lower case. I think it is small bug in TextBox control, anyway
that's how it is.


HTH
Alex
 
R

Ryan McCormack

Assuming you have a textbox named TextBox1 you need to define the
Leave event for this text box, and then write the functionality for
that function:

this.TextBox1.Leave += new System.EventHandler(this.TextBox1_Leave);

private void TextBox1_Leave(object sender, System.EventArgs e)
{
this.TextBox1.Text=this.TextBox1.Text.ToUpper();
}
 
A

AlexS

Now it's clear - you did not specify that you use Web.UI control and
everybody assumed it was WinForms one.

Then you have to hook up some available event - like Validate - and use your
code there. Or maybe css style if browser supports it - see
Customizing the Appearance of ASP.NET Server Controls Using Styles on MSDN
or in .Net help file.

HTH
Alex
 
A

andrew lowe

AlexS said:
Now it's clear - you did not specify that you use Web.UI control and
everybody assumed it was WinForms one.

Then you have to hook up some available event - like Validate - and use your
code there. Or maybe css style if browser supports it - see
Customizing the Appearance of ASP.NET Server Controls Using Styles on MSDN
or in .Net help file.


An even easier solution:
add the style attribute: text-transform: uppercase to the textbox

hth
andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Converting to UpperCase 3
upper case lower case 0
ToUpper 2
Converting Keystrokes in upper case 6
UPPER function 2
Uppercase in Combobox text 4
DataTable Select 3
Creating a derived object from a base object 10

Top