Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am new to DotNet.

In a webpage I have one Textbox name as Status.I need to restrict the user to enter only Yes or No in the Textbox.

Help me out from this

Alternatively.

I can do with dropdown but there should be only textbox.
Thanks in Advance.

Subhash G.
Posted
Updated 18-Jul-11 18:25pm
v2

If the only possibilities are Yes and No, I would consider using a CheckBox rather than text for input.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Jul-11 23:19pm    
Finally! Totally agree. Request does not make any sense at all. (This silly thing comes second time already, from what I know. What are they thinking?) More exactly, please see my answer.
--SA
Sergey Alexandrovich Kryukov 19-Jul-11 11:13am    
Walt, please look at how much blaming I got for my answer. I am quite surprised that people protect their convenience of "meeting requirements" over the inconvenience to stand for better solution and convincing customers. I added few comments. What do you think?
--SA
Dr.Walt Fair, PE 19-Jul-11 11:55am    
Well, I think there's much to do about nothing. I said I would consider using a check box, etc., but not that I would demand it. If not meeting the requirements means he won't get paid, then I fully understand.

I can control my own code, but not others, so I figure that if they've been advised, then it's up to them to decide what makes more sense in their situation.
walterhevedeich 19-Jul-11 22:43pm    
This is a better comment, rather than telling OP that the request doesn't make sense.
You can use Javascript[^] for validating your textbox. There are plenty of examples on the Internet about this.

[Update]
The link below is a good example of validating a textbox using Javascript.
http://kottawadumi.blogspot.com/2010/05/how-to-validate-textbox-using.html[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Jul-11 23:18pm    
Why, why?! Request makes no sense at all!
Please see my solution.
--SA
walterhevedeich 19-Jul-11 0:37am    
I know we can use other controls for that, but since the user mentioned that he is aware of the other possibility(use of dropdown), but still insisted on using textbox, I might as well try to show him the possibility of doing it using a textbox. It might sound silly or doesn't make sense, but this can be a requirement from his client. And we can't deny the fact that some demanding clients make silly requirements, and insist on that. IMHO, if those requirements are doable, why not do what they want? After all, they will pay us in the end.
Sergey Alexandrovich Kryukov 19-Jul-11 11:07am    
I am quite surprised. Do you think "requirements" should be met? Who told you so :-)
OK, please see my comments to the comments on my solution.
It looks we have different attitudes to life.
--SA
walterhevedeich 19-Jul-11 21:43pm    
Do you think "requirements" should be met?
Let's put it this way. Why do you think "requirements" should not be met? How bout considering the fact that software development begins with requirements gathering? What makes it more important is that these requirements are the basis of what system you will create. Later on, the same requirements will be the basis by the Quality Analysts to create test cases and procedures to ensure that the system is doing what its supposed to do. Now, to answer your question, yes, it should be met.
subhash04573 19-Jul-11 1:47am    
ya i too agree with you.
but the clien want's the textbox. wat should i do ?
Use Radio Button or Check Box. Because you have the option as Yes or No. that will be better instead of Textbox.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-11 21:42pm    
My 5. I don't understand this craze about TextBox. So many people started to protect this absurd design and down-vote (please see my solution where I also suggested Radio Button or Check Box).
--SA
Yes or No TextBox? Makes no sense at all!

1) Make two radio buttons in the same group: "Yes" and "No".

or, better yet

2) Make one check box "Confirm blah-blah...". Checked means "Yes", unchecked means "No".

That's it.

—SA
 
Share this answer
 
v2
Comments
Dr.Walt Fair, PE 18-Jul-11 23:22pm    
Yes, that's what I would do. Simple and no validation needed.
Sergey Alexandrovich Kryukov 18-Jul-11 23:26pm    
Absolutely. Thank you, Walt.
--SA
Mohammad A Rahman 18-Jul-11 23:39pm    
I agree with SA. :)
Sergey Alexandrovich Kryukov 19-Jul-11 0:24am    
Thank you, Mohammad.
--SA
[no name] 19-Jul-11 0:27am    
Good Call SA.
Hi,

This sample used AjaxControlToolkit.

Try this if could help:

  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Auto">
    </asp:ScriptManager>
    <div>
        <table width="100%">
            <tr align="left">
                <td>
                    Status:&nbsp;
               
                    <asp:TextBox ID="txtStatus" runat="server" Width="3%" MaxLength="3"></asp:TextBox>
                     
                    <cc1:FilteredTextBoxExtender ValidChars="YesNo" FilterMode="ValidChars" 
                    TargetControlID="txtStatus"
                        ID="fvtxtStatus" runat="server">
                    </cc1:FilteredTextBoxExtender>
                </td>
            </tr>
            <tr>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </td>
            </tr>
        </table>
        
    </div>
    </form>
</body>


You must have a copy of AjaxControlToolkit.dll. You may google it to have a copy...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Jul-11 23:19pm    
Why, why?! Request makes no sense at all!
Please see my solution.
--SA
Nagy Vilmos 20-Jul-11 7:17am    
He answered the question, you didn't
Al Moje 18-Jul-11 23:40pm    
I agree with asp:RegularExpressionValidator if the
solution has no reference to Ajax, but if in cases
that the application is having reference to Ajax,
the asp:RegularExpressionValidator does not work.
I had been try this...
a referrence library to Ajax,
You could try asp:RegularExpressionValidator and ^[YES|NO]*$ as RegularExpression for the validator.

and please visit this site,

RegularExpressionValidator[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Jul-11 23:20pm    
One more... Why, why?! Request makes no sense at all!
Please see my solution.
--SA
Al Moje 18-Jul-11 23:31pm    
I agree with asp:RegularExpressionValidator if the
solution has no reference to Ajax, but if in cases
that the application is having reference to Ajax,
the asp:RegularExpressionValidator does not work.
I had been try this...
a referrence library to Ajax,
Is it using Text box For Yes or No?

1) Make two radio buttons in the same group: "Yes" and "No".

2) Make one check box , Checked means "Yes", unchecked means "No".
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jul-11 23:54pm    
Why would you simply repeat my answer almost one-to-one? By the way, take a look how many down-votes I got. What do you think?
--SA
Ashika s 20-Jul-11 2:58am    
nop.............i jst gave the answer.......... not coopied from u...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900