.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

What wouldbe the best approach to accomplish validation as you enter into textbox

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

Here is what im wanting to do, i believe i have seen it done, but cant remember if it was while you were typing or at validation. But i think at validation would be fine.

We have a form that will allow you to enter an IP address. In the table, that is the primary key. I would like to validate either during the entry or upon submission if that value is already in the table, if it is, then they cannot submit.

Would it be best to use a compare validator and compare the entered value with a list of values returned from the table?

Any suggestions on how to accomplish would be great. 

View Complete Post

More Related Resource Links

How to disable textbox causing validation?

Hello I was running into a strange problem: If I left a textbox blank (in some instances) the textbox would not give up the focus (I could not even close the form).  I learnt later that this was because the text in the textbox was causing validation to fail.  I would have to type in some value (Satisfy validation) before i could close the form. This is problematic for me and I don't want the textbox to behave this way (I do not awnt front end validation).  I desire to have validation done ONLY on the back end.     I thought that I could solve this problem by changing the 'CausesValidation' property in the textbox to false.  This worked!  However it introduced a new problem.  The binding no longer worked on the Textbox.  That is, whatever value I typed in the textbox would not make it to the data set. What is the correct way in solving this problem???  I want validation to be shut off however I still (obviously) need to keep binding in tact...      

Enter the date on the WPF DatePicker input textbox instead

When i type in the date on the date picker and check it on an lostfocus event and i try to read the text or selecteddate its blank?  Am i missing something.  I assumed typing in 5/11/2010 on the input box would either show up on the controls Text or the SelectedDate, but i may be missing something   Thanks

Unable to enter the product key in the Convert License Type page (textbox is read-only)

We installed both WSS and MOSS SP2 and had planned to follow the manual fix for the known issue that the patch unexpectedly activates a trial expiration.  However, the textbox to enter the product key is read-only.  We have tried accessing this page using the normal administrator credentials as well as the farm account; no success.The SP2 issue and manual fix is detailed here, http://support.microsoft.com/default.aspx/kb/971620We were able to experience this problem on a farm running the Feb 2007 cummulative patch (version so it's not related to the SP.  But running the SP increasing the need to find the fix.Any help is appreciated,J. Aqui

Unable to enter apostrophe ( ' ) in the textbox (Asp.net C#)

Hi friends , Im unable to enter apostrophe(') in the textbox as got error message as per below . How to solve this ? Pls help .thanks     Server Error in '/' Application. ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.46-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Agriculture, forestry and fishing(cultivation of land or animals).',''','Mr','',' at line 1 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.Odbc.OdbcException: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.46-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Agriculture, forestry and fishing(cultivation of land or animals).',''','Mr','',' at line 1Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [OdbcException (0x80131937): ERROR [42000] [MySQL][OD

Textbox Changed Validation - Best practise

I think is no secret that textbox validations on the TextChanged event is no secure. I mean there are some ways to avoid the control to raise de event.   One way used by me to validate is to delegate a button click into the blur attribute. First I create a normal button into a hidden div and then add this code in the page load: TextBox1.Attributes.Add("onblur", "document.getElementByID('Button1').click())   What I want to know is the best way to validade a textbox, because on my way there are problems in the navigation because if you dont set a focus on the next control in the Button Click the TAB INDEX navigation gets corrupted, if you do, the MOUSE NAVIGATION is avoided. So.. I hope somebody can help me to find the BEST PRACTISE to validade a textbox in the textchanged momento. thanks.  

javascript for field validation on a textbox...

I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

Which is the best approach for applying business rules and basic validation like data types?

Hi Everybody   Please suggest me the best approach for applying the business rules and data type validations .Here is my choices : 1)Sequential work flow 2)State machine work flow 3)Work flow rule engine 4)Rule engine without workflow Out of above choices ,which is the best approach? Please provide me the reasons or senarioes for which is the best approach for applying the business rules and also performancewise. My requirement is : After getting the reports ,need to apply the datatype validations like valid or invalid date ...etc to the reports .And stored into Database.In the next step,need to apply the business rules to that reports in such a way that data should be good quality. Thank you very much

character limit in textbox in range validation

Hey,I am inserting some text in texbox and there is range validation set as minimum as 10 and maximun as 100. But when i run the program, though i insert the text atleast or more than 10 characters, it is showing the error message of this range validation. So I am confused how to set range so that user has to input atleast 10 character minimum ?

textbox enter press




how can I set the textbox function to do something on "Enter" button press ?

Keypress doesnt work Sad



clipboard validation before pasting into a textbox


I have a textbox with a keypress event tied to it to prevent only numbers, backspace, and 1 decimal point being entered into it. It works fine for when someone is typing into the textbox, but I also need to validate what could be pasted into the textbox from the clipboard. Right now, the pasted text could be anything, and it's giving me errors.

Here is my code so far:

private: System::Void PreventInvalidKeyOnKeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) 
			TextBox^ cur_control = dynamic_cast<TextBox^>(sender);
			// Only allow 1 decimal point (from http://www.daniweb.com/forums/thread310070.html)
			if (e->KeyChar == '.')
					if (cur_control->Text->Contains(".") && !cur_control->SelectedText->Contains("."))
						e->Handled = true;
			// Accept only digits ".", CTRL-C, CTRL-V, and the Backspace character

Button clicked event on hitting enter in any textbox




I have a WPF form with some element on it (textbox, datagrid, button...). I have an "OK" button which will handle the form when I click on it. How could I call that event handler on every "Enter"? I mean if I hit enter key in any of the form element I want to process everything like when I clicked on "OK" button.




WPF TextBox validation not appening


Hi everyone,

I'm currently developping an application in wich I'd like to validate the input in TextBox.

So I have made my code following exactly this sample : http://weblogs.asp.net/monikadyrda/archive/2009/06/24/wpf-textbox-validation.aspx

But nothing append, I have put a breakpoint in my validate method but it doesn't seem to pass through.

I have no idea of what I'm doing wrong with this.

Could you please help me?

Thanks a lot.


How to prevent Loss of Focus if there is Validation error on a textBox?

Hi i have a TextBox displayed as a TreeViewItem and when the user enters text and Tabs away or clicks somewhere else i want the control to retain focus if there is any validation error.Is there anyway i can do that? I am adding the ValidationRule to the TextBox created dynamically in code..I do see the default redborder when there is a validation error.I just want to force the user to correct the error and not go anywhere else in the app until its fixed..
Thanks in advance...

Making the Validation Error on TextBox thicker


A few of my users would like the validation error on the textbox to be more prominent. 

I have added this to my ResourceDictionary...

<Style TargetType="{x:Type TextBox}">
  <Trigger Property="Validation.HasError" Value="true">
   <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
   <Setter Property="BorderThickness" Value="3" />
   <Setter Property="FontWeight" Value="Heavy" />

The text does indeed go heavy on validation, but the red outline stays the same.  I am guessing BorderThickness is not the correct property to set.

  1. What is the appropriate property to set?
  2. Is there a place to look at what the WPF default is for TextBox Validation.HasError?

Using Enter Key with Textbox


I have a series of textboxes, and want to use Enter key to move from one to the next.  It seems I have to check for the Enter key using the textbox keydown event, and check for the Enter key.

Question 1.  Isn't there a better way to have Enter function as a Tab?

Question 2.  When I trap the Enter via KeyDown and change focus to next textbox, I get audio 'ding'.  That's usually a cue indicating an error.  Is there a way to suppress this 'ding'?


Dynamic TextBox Validation not working on dynamic DataGrid on PlaceHolder



I have a placeholder to which I programmatically add DataGrids... In the DataGrids, I programmatically add TextBoxes along with dynamic validations. Somehow, the DataGrids show up, but the dynamic validations don't work. If I set them to static, the blank space for them appears, but still, they wont work.

I'd appreciate your help on this.



Validation (ASP.Net): Attribute 'onchange' is not a valid attribute of element 'TextBox'.



I'm new to ASP.NET, C# and Visual Studio.  I do not have an IIS Server on my computer.  I do not have a registered version of Windows XP on my computer.  I got the above message after opening one of my .aspx files (someone else created it using an older version of ASP.Net) referring to the line below:


<asp:textbox id="txtOrderNumber" Runat="server" onchange="ClientOnChange();" ontextchanged="txtOrderNumber_TextChanged"></asp:textbox>

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend