Home All Groups Group Topic Archive Search About

how to validate input of a detailsview?

Author
20 Oct 2006 7:57 AM
Cas
Hi,

I use a detailsview control for inputtng data. I want to check the user
input before it is sent to the database (min. /max value, not empty, only
some values allowed ...). When clicking on the insertbutton, i want a
warning if one or more inputs are not correct and the user must have the
opportunity to correct his errors (so all the fields must remains as it).

I know it exists  e.g. "RequiredFieldValidator", but i can't link it to a
detailsview.

I tried this, but here i only can limit the length of an input.
The fields are "fld1', 'fld2' etc ...till 'fld5'

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
Dim fld,valuefld(5) As String
Dim i, tel As Integer
For i = 1 To 5
valuefld(i) = e.Values("fld" & i)
  tel=len(value1(i))
  if tel>255 then
  valuefld(i)=left(valuefld(i),255)
  end if
next
SqlDataSource1.InsertCommand =="insert into data (fld1,fld2,fld3,fld4,fld5)
values ('" & valuefld(1) ....
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub


Thansk for help
Cas

Author
20 Oct 2006 12:15 PM
Milosz Skalecki
Howdy,

DetailsView control is based on templates - controls within the template are
acessible after template is instantiated (after binding the data). Move
validation controls to the template:

<asp:DetailsView runat="server" ID="userDetails">
    <Fields>
        <asp:TemplateField>
            <InsertItemTemplate>
                <asp:TextBox runat="server" ID="userName"/>
                <asp:RequiredFieldValidator runat="server" ID="userNameValidator"
ErrorMessage="Please enter the name" ControlToValidate="userName"/>
            </InsertItemTemplate>                   
        </asp:TemplateField>
    </Fields>
</asp:DetailsView>

hope this helps

--
Milosz Skalecki
MCP, MCAD


Show quoteHide quote
"Cas" wrote:

> Hi,
>
> I use a detailsview control for inputtng data. I want to check the user
> input before it is sent to the database (min. /max value, not empty, only
> some values allowed ...). When clicking on the insertbutton, i want a
> warning if one or more inputs are not correct and the user must have the
> opportunity to correct his errors (so all the fields must remains as it).
>
> I know it exists  e.g. "RequiredFieldValidator", but i can't link it to a
> detailsview.
>
> I tried this, but here i only can limit the length of an input.
> The fields are "fld1', 'fld2' etc ...till 'fld5'
>
> Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
> DetailsView1.ItemInserting
> Dim fld,valuefld(5) As String
> Dim i, tel As Integer
> For i = 1 To 5
>  valuefld(i) = e.Values("fld" & i)
>   tel=len(value1(i))
>   if tel>255 then
>   valuefld(i)=left(valuefld(i),255)
>   end if
> next
> SqlDataSource1.InsertCommand =="insert into data (fld1,fld2,fld3,fld4,fld5)
> values ('" & valuefld(1) ....
> SqlDataSource1.ProviderName = "System.Data.OleDb"
> End Sub
>
>
> Thansk for help
> Cas
>
>
>
>
Author
20 Oct 2006 4:05 PM
André
Thanks

Show quoteHide quote
"Milosz Skalecki" <mily***@REMOVEITwp.pl> schreef in bericht
news:F2A77B53-D6FA-49E7-B731-41C161E7FEDD@microsoft.com...
> Howdy,
>
> DetailsView control is based on templates - controls within the template
> are
> acessible after template is instantiated (after binding the data). Move
> validation controls to the template:
>
> <asp:DetailsView runat="server" ID="userDetails">
> <Fields>
> <asp:TemplateField>
> <InsertItemTemplate>
> <asp:TextBox runat="server" ID="userName"/>
> <asp:RequiredFieldValidator runat="server" ID="userNameValidator"
> ErrorMessage="Please enter the name" ControlToValidate="userName"/>
> </InsertItemTemplate>
> </asp:TemplateField>
> </Fields>
> </asp:DetailsView>
>
> hope this helps
>
> --
> Milosz Skalecki
> MCP, MCAD
>
>
> "Cas" wrote:
>
>> Hi,
>>
>> I use a detailsview control for inputtng data. I want to check the user
>> input before it is sent to the database (min. /max value, not empty, only
>> some values allowed ...). When clicking on the insertbutton, i want a
>> warning if one or more inputs are not correct and the user must have the
>> opportunity to correct his errors (so all the fields must remains as it).
>>
>> I know it exists  e.g. "RequiredFieldValidator", but i can't link it to a
>> detailsview.
>>
>> I tried this, but here i only can limit the length of an input.
>> The fields are "fld1', 'fld2' etc ...till 'fld5'
>>
>> Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e
>> As
>> System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
>> DetailsView1.ItemInserting
>> Dim fld,valuefld(5) As String
>> Dim i, tel As Integer
>> For i = 1 To 5
>>  valuefld(i) = e.Values("fld" & i)
>>   tel=len(value1(i))
>>   if tel>255 then
>>   valuefld(i)=left(valuefld(i),255)
>>   end if
>> next
>> SqlDataSource1.InsertCommand =="insert into data
>> (fld1,fld2,fld3,fld4,fld5)
>> values ('" & valuefld(1) ....
>> SqlDataSource1.ProviderName = "System.Data.OleDb"
>> End Sub
>>
>>
>> Thansk for help
>> Cas
>>
>>
>>
>>