Saturday, March 24, 2012

Validation in FormView

Hello!

I was trying out the FormView control, and it seems to work really well. But when trying to use validators (e.g. RequiredFieldValidator) I don't get the expected results.

What I do is inserting a

<asp:Button>
and on this i set properties like so

<asp:Button runat="server" CausesValidation="true" ValidationGroup="InsertValGroup" CommandName="Insert" />

This causes no validation on the page, so what could I be doing wrong? Yes, I've doublechecked that the validation group is the right one.

Thanks in advance,
PatrickI have no problem with that. Here is my code:


CompanyName:
<asp:TextBox Text='' Runat="server" ID="CompanyNameTextBox"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" ErrorMessage="RequiredFieldValidator"
ControlToValidate="CompanyNameTextBox" ValidationGroup="test">
</asp:RequiredFieldValidator>
<asp:Button ID="Button1" CommandName="Insert" Runat="server" Text="Button" ValidationGroup="test" />

Can you please post your code so I can see if you are doing something wrong.
Hello again!

The code I'm using is as follows (for the InsertTemplate which doesn't work):


<InsertItemTemplate>
<table width="100%" cellpadding="0" cellspacing="0"><tr height="30">
<td width="180">
Titel</td>
<td style="width: 382px">
<asp:TextBox Text='<%# Bind("Titel") %>' Runat="server" ID="titelText" Width="350"></asp:TextBox>
<asp:RequiredFieldValidator ID="titleValidator" Runat="server" ErrorMessage="*" ControlToValidate="titelText"
ValidationGroup="InsertValGroup">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr height="30">
<td width="180">
ISBN-nummer</td>
<td style="width: 382px">
<asp:TextBox Text='<%# Bind("ISBN") %>' Runat="server" ID="isbnText" Width="250"></asp:TextBox><br />
</td>
</tr>
<tr height="30">
<td width="180">
Kategori</td>
<td style="width: 382px">
<asp:DropDownList ID="categoryList" Runat="server" DataSourceID="CategoriesSource"
Width="170px" Height="22px" DataTextField="Navn" DataValueField="ID" SelectedValue='<%# Bind("Type") %>'>
</asp:DropDownList>
</td>
</tr>
<tr height="30">
<td width="180">
Pris</td>
<td style="width: 382px">
<asp:TextBox Text='<%# Bind("Pris") %>' Runat="server" ID="priceText"></asp:TextBox>
<asp:RequiredFieldValidator ID="priceValidator" Runat="server" ErrorMessage="*" ControlToValidate="priceText"
ValidationGroup="InsertValGroup">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr height="30">
<td width="180">
Billede</td>
<td style="width: 382px">
<asp:TextBox Text='<%# Bind("Billede") %>' Runat="server" ID="pictureText" Width="350"></asp:TextBox>
<asp:RequiredFieldValidator ID="pictureValidator" Runat="server" ErrorMessage="*"
ControlToValidate="pictureText" ValidationGroup="InsertValGroup">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="padding-top: 6px" valign="top" width="180">
Beskrivelse</td>
<td style="padding-top: 6px; width: 382px;">
<asp:TextBox Text='<%# Bind("Beskrivelse") %>' Runat="server" ID="descriptionText" Columns="45"
Rows="10" TextMode="MultiLine" />
</td>
</tr>
<tr>
<td style="padding-top: 6px" valign="top" width="180">
Engelsk beskrivelse</td>
<td style="padding-top: 6px; width: 382px;">
<asp:TextBox Text='<%# Bind("EnBeskrivelse") %>' Runat="server" ID="enDescriptionText" Columns="45"
Rows="10" TextMode="MultiLine" />
</td>
</tr></table>
<div align="center" style="margin-top: 20px">
<asp:Button Runat="Server" ID="insertButton" ValidationGroup="InsertValGroup" Text="Tilføj" CssClass="Button" CommandName="Insert" />
</div>
</InsertItemTemplate>

No comments:

Post a Comment