ASP.NET Datalist validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I'm now very frustrated, I've been battling all of today to try and understand the datalist, editing, inserting, updating, etc, I have managed to get most of that sort of stuff working(Thank goodness:)). But now I would like to implement validation on my datalist, but I am just not getting it right :(( I have got labels in my item template wich of course hold the data coming from my database. I also have a button called edit and when that is clicked, it basically "turns the labels into textboxes" so that I can edit the values,and I successfully save those new values to the database. What I want to have is a RequiredFieldValidator on the edit text boxes, I have already created the RFV's and assigned them to the relevant textboxes, but as soon as I hit the edit button, I get an ASP error telling me NullReferenceExcepetion - the object reference is not set to an instance of an object!

This has been buggin me all damn day and I just can't seem to come right:(( I thought that perhpas it wasn't declared in the codebehind, but it is, I have inserted the RFV tags in the HTML side(directly after the textboxes that I want it to validate!) but still I get the same error

anyone got any suggestions?

Thanks
Kevin
 
Hi Kevin,

You should post the code, the definition of the templatecolumn.

Here is a piece of code from a datagrid control where I do what you need,
maybe it can help you. if not post the code.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



<asp:templatecolumn ItemStyle-VerticalAlign="Middle" ItemStyle-Width="130"
ItemStyle-HorizontalAlign="left" ItemStyle-CssClass="comunrow">
<itemtemplate>
<asp:Label Runat="server" Text='<%#
((CtpUser)Container.DataItem).Login%>' ID="Label23"></asp:Label><br>
<asp:Label Runat="server" Text='<%#
((CtpUser)Container.DataItem).FullName%>' ID="Label8"></asp:Label>
</itemtemplate>
<EditItemTemplate>
<asp:TextBox CssClass="text" Runat="server" ID="loginTXT"
Text='<%# ((CtpUser)Container.DataItem).Login%>'></asp:TextBox>
<asp:CustomValidator id="Customvalidator2"
ControlToValidate="loginTXT"
OnServerValidate="ServerValidation"
ClientValidationFunction="IMValidator"
Display="Static"
ValidateIfBlank="yes"
ErrorMessage="*"
PopUPMessage="The Login field can not be null"
runat="server"/><br>
<asp:TextBox CssClass="text" Runat="server" ID="fullnameTXT"
Text='<%# ((CtpUser)Container.DataItem).FullName%>'></asp:TextBox>
<asp:CustomValidator id="Customvalidator1"
ControlToValidate="fullnameTXT"
OnServerValidate="ServerValidation"
ClientValidationFunction="IMValidator"
Display="Static"
ValidateIfBlank="yes"
ErrorMessage="*"
PopUPMessage="The name field can not be empty"
runat="server"/>
</EditItemTemplate>
</asp:templatecolumn>







Kevin said:
Hi all,

I'm now very frustrated, I've been battling all of today to try and
understand the datalist, editing, inserting, updating, etc, I have managed
to get most of that sort of stuff working(Thank goodness:)). But now I would
like to implement validation on my datalist, but I am just not getting it
right :(( I have got labels in my item template wich of course hold the data
coming from my database. I also have a button called edit and when that is
clicked, it basically "turns the labels into textboxes" so that I can edit
the values,and I successfully save those new values to the database. What I
want to have is a RequiredFieldValidator on the edit text boxes, I have
already created the RFV's and assigned them to the relevant textboxes, but
as soon as I hit the edit button, I get an ASP error telling me
NullReferenceExcepetion - the object reference is not set to an instance of
an object!
This has been buggin me all damn day and I just can't seem to come
right:(( I thought that perhpas it wasn't declared in the codebehind, but it
is, I have inserted the RFV tags in the HTML side(directly after the
textboxes that I want it to validate!) but still I get the same error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top