Home All Groups Group Topic Archive Search About

Formfields in Repeaters - validation and save into DB

Author
6 Dec 2006 5:07 PM
Rafal
Hello,

I have a repeater, which generated form fields:

<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />

<asp:Repeater ID="RepeaterRevenues1" runat="server"
DataSourceID="Revenues1DataSource">
  <ItemTemplate>
    <asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="CustomValidator"
            OnServerValidate="CustomValidator_ServerValidate"
ControlToValidate="TextBoxQuota"></asp:CustomValidator>

    <asp:TextBox ID="TextBoxQuota" runat="server" Text='<%# Bind("Quota")
%>'></asp:TextBox>
  </ItemTemplate>
</asp:Repeater>

Wenn I press Button1 then validation is called (in
CustomValidator_ServerValidate).
It checks if data are valid and I set isValid = false or true.

Then method is called:
Button1_Click

and here I have problems ...
In the method Button1_Click ... how can I check if validation is false or
true ?
Method CustomValidator_ServerValidate is called a few times - 1 time for
every loop-cycle.

When isValid is false at least one time then whole form won't be valid.

And how can I read the data from form fields ? (I'd like to save them in the
DB).
RepeaterRevenues1.FindControl doesn't give me right results.

Thank you for help in advance.

with best regards,
Rafal

Author
6 Dec 2006 7:55 PM
Robert Bernhardt
Rafal schrieb:
Show quoteHide quote
> I have a repeater, which generated form fields:
>
> <asp:Button ID="Button1" runat="server" Text="Button"
> OnClick="Button1_Click" />
>
> <asp:Repeater ID="RepeaterRevenues1" runat="server"
> DataSourceID="Revenues1DataSource">
>   <ItemTemplate>
>     <asp:CustomValidator ID="CustomValidator1" runat="server"
> ErrorMessage="CustomValidator"
>             OnServerValidate="CustomValidator_ServerValidate"
> ControlToValidate="TextBoxQuota"></asp:CustomValidator>
>            
>     <asp:TextBox ID="TextBoxQuota" runat="server" Text='<%# Bind("Quota")
> %>'></asp:TextBox>
>   </ItemTemplate>
> </asp:Repeater>
>
> Wenn I press Button1 then validation is called (in
> CustomValidator_ServerValidate).
> It checks if data are valid and I set isValid = false or true.
>
> Then method is called:
> Button1_Click
>
> and here I have problems ...
> In the method Button1_Click ... how can I check if validation is false or
> true ?
> Method CustomValidator_ServerValidate is called a few times - 1 time for
> every loop-cycle.
>
> When isValid is false at least one time then whole form won't be valid.
>
> And how can I read the data from form fields ? (I'd like to save them in the
> DB).
> RepeaterRevenues1.FindControl doesn't give me right results.

Hi

if you iterate every rendered row, you can get the controls by FindControl

ex. VB.Net (not tested)

Dim cItem As RepeaterItem = Nothing
For Each cItem In RepeaterRevenues1
   Dim cValidator AS CustomValidator =
CType(cItem.FindControl("CustomValidator1"), CustomValidator)
   ....
Next

rb
Author
7 Dec 2006 8:37 AM
Rafal
Hi,

it helped, now my problem is solved :-)
Thank you very much.

with best regards,
Rafal