Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create a text box validation variable
Message
De
08/08/2017 06:28:18
 
 
À
07/08/2017 19:00:47
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Divers
Thread ID:
01653138
Message ID:
01653144
Vues:
44
>Hi,
>
>Say I have text box (asp:textbox) on a page which has a RequiredFieldValidator so that the text box cannot be left blank.
>
>And then I have a validation method that checks if the user entry is valid; that is, if DB has this entry in the table. If user enters wrong value, the page says "Invalid Entry - blablabla".
>
>But the user can still click on Submit button. And since the RequiredFieldValidator will not stop it (some "bad" entry is in the text box), the Submit click method will fire. I want to prevent it.
>
>So, when the code validation method check for a valid entry (in code behind) and find that the entry is not valid, I want to set a flag that will prevent Submit to fire.
>
>How do you do it?

This is what I figured to be the solution (unless the gurus here will tell me otherwise). First, I didn't want to have the validation code firing twice, once when user enters something in the text box and another time in Submit click().

The form has a textbox which is set with the message "Entry Not Found" if user enters an invalid text. So, along with setting this text (Entry Not Found), I set the ForeColor of the textbox to Red. If the entry is found, I set it to the System default.
Then in the Submit Click method I check if the ForeColor of the textbox is Red. And if so, do not proceed with the code in the Submit click()
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform