473,328 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,328 software developers and data experts.

Set or raise Validation.HasError to highlight textbox from a method...

Hi.

I have a textbox that have a binding on it with converter and validationrules.

When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers that are connect to it and it works as it should..

What I wanna to do it in some special case I wan to test tb.Text.Equals("myTestStr") or if the text lenght too large etc.. and I wanna same behave as a validation has error on the textbox if the textbox not ok on check, if understand what i mean.

For examble.

Expand|Select|Wrap|Line Numbers
  1. private void OnTargetUpdated(object sender, DataTransferEventArgs e)
  2.         {
  3.             if (sender is TextBox)
  4.             {
  5.                 TextBox tb = sender as TextBox;
  6.                 BindingExpression bindExp = tb.GetBindingExpression(TextBox.TextProperty);
  7.  
  8.                 if (tb.text.lenght > 10)
  9.                 {
  10.  
  11.                     XsToLargeRule rule = new XsToLargeRule();
  12.  
  13.                     ValidationError validationError = new ValidationError(rule, bindExp);
  14.  
  15.                     validationError.RuleInError = rule;
  16.                     validationError.ErrorContent = "TOO LARGE STRING";
  17.  
  18.                     tb.Text = "########";
  19.                     Validation.MarkInvalid(bindExp, validationError);
  20.                     tb.UpdateLayout(); 
  21.                 }
  22.             }
  23.         }
XsToLargeRule is a dummy method that allways return new System.Windows.Controls.ValidationResult(false, "Too Large string");

But it is not working. The textbox text changed to "#####" but with no style foreground change.

Please help, what I wanna to know is how to mark a textbox as invalid that have validation error from code behind and trigger the style change without useing binding generate validationrules.
Oct 30 '09 #1
4 8183
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 30 '09 #2
tlhintoq
3,525 Expert 2GB
I doubt this is the code you are actually compiling and using.
Line 8. the property is .Length not .lenght That will throw an error right there and not run.
Oct 30 '09 #3
Tnx for the tip and correction.. the code is just for a examble

But the question still are the same I will somehow set a textbox to have validation error with a error message and trigger style change.


Excuse me for my bad english :)
Oct 30 '09 #4
tlhintoq
3,525 Expert 2GB
Your English is fine. Far better than my foreign language skills.

the code is just for a examble
That may be, but its hard to help fix someone's code when it isn't actually the code they are using and having the problem with.

If you put a breakpoint at line 18 and walk through the code line by line do you find any errors being thrown? Maybe the validation your are creating and throwing isn't formed correctly? Does the validation error event get triggered when you throw the .MarkInvalid ?
Oct 30 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ellen Manning | last post by:
Using A2K. I've developed a survey form with a number of questions that have 6 possible responses each. The possible values are 5 (Strongly Agree) down to zero (No Response). I want to develop...
2
by: ALI-R | last post by:
I have a text box where user is supposed to enter a URL , How can I programmatically figure out the a URL that user has been entered is valid or not ,I mean wethere it exist or not???? thanks
2
by: Matthew Wieder | last post by:
Hi - I'm trying to do client-side validation of the text in a Asp.Net textbox control using javascript. My page has the following: <form id="Form1" method="post" runat="server" onsubmit="return...
5
by: Gary Vidal | last post by:
I have a client side Javascript which checks an OrderQuantityField against a hidden Textbox of the Minimum Order Quantity. I dont want to do validation on a postback. I would like to be able to...
2
by: Anand Sagar | last post by:
My program requirement is to create 2 textboxes at run time. When the cursor leaves the first textbox, (i guess the TextChange event) I want something to occur (post data into database) Problem...
2
by: tshad | last post by:
Is there a way to raise an event when a user exits a textbox? I tried OnTextChanged and that doesn't seem to do it. <asp:textbox id="email" TextMode="SingleLine" OnTextChanged="checkRecords"...
6
by: salo | last post by:
Can anybody say me for writing javascript code for textbox key press event such a way that it should allow only alphabets,dot and spaces
1
by: vayalumkan | last post by:
I have the following program (C# VS 2005) for validating an email id entered in a textbox. It works fine. Namespace used - using System.Text.RegularExpressions; At present I have written...
2
by: Christian Cambier | last post by:
Hello, I have a textbox in which I only want to display numbers when the focus is set on the textbox and the user presses a key on the kb. Easy with html-control <input id="htmlTxtVal2"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.