CustomValidator in Datagrid ItemTemplate


  I have a datagrid that has two item templates,
     1.) with a drop down list
     2.) with a textbox and CustomValidator

  On the postback I am iterating through the datagrid and ensuring that the text box is filled for certian selections in the drop down list.  
 
  When I find one that is in error I set the custom validator as such.
 
  validTest.ErrorMessage = "testing summary validator";
  validTest.IsValid = false;

  Unfortunately within the datagrid the validator does not appear "*" and the summary validator does not appear with the text.

   If I use a CustomValidator in the same fashion and same section of code that resides outside of the datagrid, the validator works as I expected.

  Anyone have any thoughts on this.  

  Thanks for the read.

LVL 2
dlarlickAsked:
Who is Participating?
 
ryerrasConnect With a Mentor Commented:
Hmm. its the travesty of event modelling in asp.net. Their design is not completely fool proof. Recently I had the same problem. I was using datagrid to handle some data, then I was trying to bind server side errors to the validation summary control using the ErrorMessage property of CustomValidator. Unfortunately, it never worked.
So, I created a custom control with the guidance from the following article, it worked seemlessly. Now, my server side errors bind as expected to the validation summary. Read through the article and let me know if you have any questions. I am using the approach in this article to solve this problem, in a live application. So, trust me it works

http://www.codeproject.com/aspnet/validationsummary.asp
0
 
dlarlickAuthor Commented:

  Thanks for the post.
 
  I will take a look later today when I have some time.  



     
0
 
dlarlickAuthor Commented:

  Thank you...

   Will do the trick...  I'll have to use a label next to the textbox, but I don't see any other alternatives.

   Works well and solves another issue that I had nagging me elsewhere.

   Gold Star!!
0
All Courses

From novice to tech pro — start learning today.