473,586 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set or raise Validation.HasE rror to highlight textbox from a method...

4 New Member
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.Valida tionResult(fals e, "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 8212
tlhintoq
3,525 Recognized Expert Specialist
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 Recognized Expert Specialist
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
HenrikL
4 New Member
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 Recognized Expert Specialist
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
1974
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 a report that looks like this: <Question 1 text> Strongly Agree Somewhat Agree ..... No Response <Count of 5's> <Count of 4's> ...
2
3278
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
17511
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 validateName(this);"> and <script language="JavaScript"><!-- function validateName(theForm) {
5
2151
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 have FormValidate Javascript function postback to my addToCart Method in my code behind function ValidateForm(myform) { if...
2
3113
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 is that in Which event of the Webform do I create the run-time textboxes ? Also, how can I raise the events ? Please check my code, give...
2
4127
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" Columns="45" runat="server" /> I need to load a dropdownlist after someone enters his email. There would be no button to push. After the user...
6
4411
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
2622
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 the functionality inside textBox1_Validating event as shown below and when I click button1(my form contains button control called button1), it is...
2
2002
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" type="text" onkeypress="return NoNumbers(event)" and javascript (implement the onkeypres event handler) But how to implement it when using the...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.