.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

How to disable textbox causing validation?

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :Windows Application
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...      

View Complete Post

More Related Resource Links

Disable "Paste" lable on read only textbox.

Hi, I am new to C# .NET. I am facing very small problem. i.e. I made a text box with readonly option. Now this text box is not allowing to paste,ok its working fine. But when i give mouse right click paste lable is enable. Can you guide me how to disable this lable. With Regards Srinubabu

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>

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 ?

Disable copy paste in textbox without Javascript




Can you somebody help me in disabling copy paste in the textbox without using Javascript for an web application?




disable COPY/Paste function on a textbox

Hi, I want to make disable COPY/Paste function on a textbox. DO u know how to do it if so please let me know asap? And it is required to be done at client side. The text box can be HTML or ASP:TextBox. Please reply asap.

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


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. 

validation group one elemetn disable


My scenario is,

I have a two radio button on the page and under that four dropdown and one text field.

I made a single validation group for all the field.

Now when selecting the second radio button then fourth dropdown will be invisible and a text field will be display on that positon.

I made all that using javascript.

Now the problem is when selecting the second radio button the fourth field is not visible.

But after selecting all the mandatory fields it again ask for the fourth dropdown. how can I made only that particular field out of that group when its not displaying?

I need all using javascript. 

Listview selecteditem binding to textbox causing problems




I have listview and i have binded the listview selected item to a grid's datacontext. The grid contains a text box whose text property is bound to one of the columns in the listview. I have Add, Edit and Delete buttons to manipulate data in the listview.


Whenever i change the selected item in the listview the text in the textbox is changing. Since by default the binding is two way if i edit the data in the textbox it is reflectedi in the listview. But upon clicking on the cancel button the textbox value is not reverted back to old value. The list view itemsource is bound to an object of the class BindingListCollectionView

Code in button click event where BindingDetails is object of calss BindingListCollectionView. But this code does not rollback the changes in the textbox.


btnCancel_Click(object sender, EventArgs E)
  if(IsEdit == true)


I tried the following things.

Trying to get the Text depe

How to disable ESC key validation in ASP.NET 2.0


I have a page that has a submit button which causes validation and a cancel button which does not cause validation.

When the cancel button is clicked, the button's click event handler is executed with no problem.

I would like the ESC key to do exactly what the cancel button does.

What we do is to trap the ESC key and then raise the click event for the cancel button. 

Our code to handle the ESC key works fine except when the page has a validator.

When the page has a validator, the cancel button click event handler never gets called after the ESC key is pressed.

It works fine when the cancel button is clicked.

It also works fine if we do the same thing and trap any other key. 

So it has something to do the ESC key and validation.

Any ideas would be appreciated.


A __ViewState field is being posted to my form and causing validation to fail. How do I ignore this?


I'm implementing a payment gateway, and it basically works like this:

User will do their shopping at my site, and view Cart.aspx. Cart.aspx will post the form to the payment gateway.

The payment gateway will process the payment, and then do a post back to my server at Response.ashx. It posts the details of the credit card transaction, but it will also re-post whatever I gave it. So it is giving me back a __ViewState field. (ViewState, EventValidation, RequestValidation are all disabled on both Cart.aspx, and Order.aspx, which is the page being redirected to.)

Response.ashx has the following code:

public class Response: IHttpHandler, IRequiresSessionState
public void ProcessRequest(HttpContext context)
new ResponsePresenter

public void

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

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...

How to disable resize grip on multiline textbox?


I cannot seem to find what should be a simple setting to keep my multiline textbox to the height/width or row/column settings without the resize grip or ability to resize. How do I prevent resizing?

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?

How to disable a validator that associates with a disabled textbox?


 Hi there,

If a control is disabled (enabled = false), will the validator controls associated with it automatically know not to carry out validation?

i have a checkbox and a textbox, if the checkbox is checked, the textbox is enabled, and has to have a value, where i used a required field validator.

but if the checkbox is not checked, textbox is then disabled, however, the validator controls still seem to be trying to validate the disabled textbox.

so is there a way to disable validator according to textbox's state? such as textbox.enable = true? seems like causevalidation method requires multiple button, however i only need one...


thanks in advance!

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