Converting to Upper Case

  • Thread starter Thread starter Brian Conway
  • Start date Start date
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?
 
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
 
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.
 
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;
 
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;
 
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
 
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();
}
 
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
 
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

Back
Top