Home All Groups Group Topic Archive Search About

Can I Use RequiredFieldValidator inside a repeater ?

Author
19 Jan 2007 5:31 AM
bhavesh
Hello,

I use a repeater to display "Name" and "Order". I hope that users can
change
the "Order" field from the browser. And, if they input invalid value
(such
as string) in the "Order" field, I hope the validator control can alert

them. Can I do this with repeater? Or I should use other webcontrol?


Thanks,
Simon


---------------------------------------------------------------------------­-

-------
<asp:repeater id="repeater1" runat="server">
    <HeaderTemplate>
        <table>
            <TR class="gridHead">
                <TD nowrap>Name</TD>
                <TD nowrap>Order</TD>
            </TR>
    </HeaderTemplate>
    <ItemTemplate>
            <TR class="gridItem" valign="top">
                <TD<%# DataBinder.Eval(Container.DataItem, "Name")
%></TD>
                <TD>
                    <asp:textbox id="txtOrder" runat="server"
value="<%#
DataBinder.Eval(Container.DataItem, "Order") %>" />
                    <asp:RequiredFieldValidator ID="valOrder"
Runat="server"
ControlToValidate="txtOrder" ErrorMessage="Cannot be empty." />
                </TD>
            </TR>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
<asp:repeater>
<asp:Button ID="btnSubmit" Runat="server" Text="Submit" />

Author
19 Jan 2007 1:14 PM
Scott M.
Repeaters are read only interfaces and don't have a mechanism to switch them
from read only view into edit view (templates).  If that is what you need,
you should consider a DataList or a DataGrid.

RequiredFieldValidators won't check the data to see if it is a string, it
will only check to see if there is *some* data.  If you need the field to be
required AND you need it to be a specific data type, then you'll need 2
validators (a RequiredFieldValidator and a RangeValidator) associated with
the one input field.

Lastly, yes, you can nest validators inside of DataList and DataGrid
controls (as mentioned you wouldn't put them into Repeaters since repeaters
aren't for data input).


"bhavesh" <bhavesh.***@gmail.com> wrote in message
news:1169184718.232385.143450@a75g2000cwd.googlegroups.com...
Hello,

I use a repeater to display "Name" and "Order". I hope that users can
change
the "Order" field from the browser. And, if they input invalid value
(such
as string) in the "Order" field, I hope the validator control can alert

them. Can I do this with repeater? Or I should use other webcontrol?


Thanks,
Simon


---------------------------------------------------------------------------­-

-------
<asp:repeater id="repeater1" runat="server">
    <HeaderTemplate>
        <table>
            <TR class="gridHead">
                <TD nowrap>Name</TD>
                <TD nowrap>Order</TD>
            </TR>
    </HeaderTemplate>
    <ItemTemplate>
            <TR class="gridItem" valign="top">
                <TD<%# DataBinder.Eval(Container.DataItem, "Name")
%></TD>
                <TD>
                    <asp:textbox id="txtOrder" runat="server"
value="<%#
DataBinder.Eval(Container.DataItem, "Order") %>" />
                    <asp:RequiredFieldValidator ID="valOrder"
Runat="server"
ControlToValidate="txtOrder" ErrorMessage="Cannot be empty." />
                </TD>
            </TR>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
<asp:repeater>
<asp:Button ID="btnSubmit" Runat="server" Text="Submit" />
Author
19 Jan 2007 3:08 PM
bhavesh
THanks a lot dear Scott.

U solved my total confusion. its preety explaination.

thanks again a lot.
Author
19 Jan 2007 5:47 PM
Scott M.
No problem.  Good luck with your project.

-Scott


Show quoteHide quote
"bhavesh" <bhavesh.***@gmail.com> wrote in message
news:1169219285.653749.118310@38g2000cwa.googlegroups.com...
> THanks a lot dear Scott.
>
> U solved my total confusion. its preety explaination.
>
> thanks again a lot.
>