FormView and CustomValidator

This is a discussion on "FormView and CustomValidator" within the ASP.NET Forum section. This forum, and the thread "FormView and CustomValidator are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 15th, 2007, 08:35
New Member
Join Date: Mar 2007
Location: italy
Age: 32
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
FormView and CustomValidator

Hi to all!
I've got this problem, I'm thinking on it for about 2 days, searching info on the web ... but nothing.

Here's the problem: I've got a long FormView control that works fine. I added a lot of RequiredFieldValidator on a lot of fields and all works fine: when I click the FormView "InsertButton", the page reloads and I see that all the RequiredFieldValidator worked fine.

But I need to use also a lot of CustomValidator. I tried first the "client-side" style, using JavaScript functions and it worked ok. But my web-admin told me I can't use client-side validation: I can't use JavaScript due to accessibility issues.

Well, this is not a problem! I switched to server-side validation ... but it doesn't work at all! The server-side function is never called! Here's the code:

Code: Select all
<asp:FormView ID="fv" runat="server" AllowPaging="True" DataKeyNames="id" DataSourceID="dsMain"
            DefaultMode="Insert" Width="760px">
...
<InsertItemTemplate>
   ...
   <asp:TextBox ID="s1a2altroTextBox" runat="server" Text='<%# Bind("s1a2altro") %>' Enabled="False" Width="400px" MaxLength="100"></asp:TextBox>
   <asp:CustomValidator ID="s1a2altroCV" runat="server" ErrorMessage="CustomValidator" OnServerValidate="s1a2altroFV">Not ok</asp:CustomValidator>
   ...
   <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="GO!"></asp:LinkButton>
</InsertItemTemplate>
...
</FormView>
and here's the Sub:

Code: Select all
Sub s1a2altroFV(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim t1 As TextBox
        t1 = fv.FindControl("s1a2altroTextBox")
        lblTest.Text = t1.Text
        args.IsValid = False
End Sub
Please help me I need to finish this work for tomorrow! (I hate this kind of work!) Thank you in advance.
Reply With Quote

  #2 (permalink)  
Old Mar 29th, 2007, 16:23
Junior Member
Join Date: Mar 2007
Location: California
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: FormView and CustomValidator

i dont see where you told it what control to validate. for example in your custom validator:

ControlToValidate="s1a2altroTextBox"

so as a rough example:

Code: Select all
<asp:FormViewID="FormView1"runat="server">
<ItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:CustomValidatorID="CustomValidator1"runat="server"ControlToValidate="TextBox1"
ErrorMessage="CustomValidator"></asp:CustomValidator>
</ItemTemplate>
</asp:FormView>

Last edited by karinne; Mar 30th, 2007 at 15:06. Reason: Please use [code]...[/code] tags when displaying code!
Reply With Quote
  #3 (permalink)  
Old Mar 29th, 2007, 16:31
Junior Member
Join Date: Mar 2007
Location: California
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: FormView and CustomValidator

I see what your trying to do.. but the OnServerValidate="s1a2altroFV" will never get called unless it's attached to something. so it does have to be attached to something. when you assign it's ControlToValidate="" you should also set EnableClientScript="False" to ensure it does not perform this client side.
Reply With Quote
Reply

Tags
formview customvalidator

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
VWD FormView InsertItemTemplate CustomeEditor CliveMM ASP.NET Forum 0 Aug 24th, 2007 14:44


All times are GMT. The time now is 15:50.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43