Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Toggle Y or N instead of TRUE or FALSE in texbox
Message
From
16/09/2008 03:38:54
 
 
To
15/09/2008 14:56:54
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01345710
Message ID:
01347832
Views:
7
Hi,

I guess the best solution depends on where in the 'supply-chain' it would be best to apply the conversion in your case. But doing it all in the Textbox does have the advantage of combining the validation and conversion in one place. Of course, if you are going to subclass a Textbox for this then it would probably make sense to use a custom property rather than the Tag property (which may come in handy for a more generic use somewhere down the line)

Best,
Viv

>Another option (I'm up to six now): Lingzhi suggested I look at the tag property to track the real value of the textbox and then display "Y" or "N" and it works as well:
>
>
>public class YesNoBox : TextBox  
>
>    {  
>
>        private Char spaceChar;  
>
> 
>
>        public YesNoBox()  
>
>        {  
>
>            this.spaceChar = Convert.ToChar(" ");  
>
>            this.Tag = "TRUE";  
>
>            this.KeyPress += new KeyPressEventHandler(YesNoBox_KeyPress);  
>
>        }  
>
> 
>
>        void YesNoBox_KeyPress(object sender, KeyPressEventArgs e)  
>
>        {  
>
>            if (e.KeyChar == spaceChar)  
>
>            {  
>
>                ToggleDisplay();   
>
>            }  
>
>            else if (e.KeyChar == 'N' || e.KeyChar == 'n')  
>
>            {  
>
>                base.Tag = "FALSE";  
>
>                base.Text = "N";  
>
>            }  
>
>            else if (e.KeyChar == 'Y' || e.KeyChar == 'y')  
>
>            {  
>
>                base.Tag = "TRUE";  
>
>                base.Text = "Y";  
>
>            }  
>
>            e.Handled = true;  
>
>        }  
>
> 
>
>        private void ToggleDisplay()  
>
>        {  
>
>            switch (this.Tag.ToString())  
>
>            {  
>
>                case "TRUE":  
>
>                    base.Tag = "FALSE";  
>
>                    base.Text = "N";  
>
>                    break;  
>
>                case "FALSE":  
>
>                    base.Tag = "TRUE";  
>
>                    base.Text = "Y";  
>
>                    break;  
>
>                default:  
>
>                    base.Tag = "ERROR";  
>
>                    base.Text = "ERROR";  
>
>                    break;  
>
>            }  
>
>        }  
>
>    }   
>
Previous
Reply
Map
View

Click here to load this message in the networking platform