473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

ASP.NET Datalist validation

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
Nov 16 '05 #1
1 4753
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" <Ke***@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
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

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rufus | last post by:
I have added some javascript to a button which is built in the MyDataList_ItemCreated event. It produces the following code which works (ie the EnableValidators function fires): <input...
1
by: Hrvoje Vrbanc | last post by:
Hello all, I have a DataList control displaying data from the database (some products). There are also TexBox controls and ImageButton controls in the two columns of the DataGrid. I would like...
0
by: ani | last post by:
I have few questions regarding datalist control. 1) How do I retrieve the values that are present in the datalist control. My aspx page actually reloads to itself, and the datalist control has...
1
by: moondaddy | last post by:
I have a datalist that makes use of the edit template. In this template I also have client side validation controls for required fields. My problem is that when I click on the cancel button it...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
3
by: Ben | last post by:
Hi, I have a page with a datagrid that you have to scroll to see. I'm using the StrengthControls SmartScroller as recommended to maintain my scroll position. Anyway, inside the datagrid I have...
0
by: ghafranabbas | last post by:
This is how you use the customvalidator control in any INamingContainer interface control (Datagrid, DataList, DataRepeater, etc). 1. In the ItemTemplate, place your customvalidator 2. Set the...
0
by: Jim in Arizona | last post by:
Is there an easier way to make a datalist aware of line breaks within text fields? I have a text box that users can type into. If they press the enter key a few times, VB sees this as a vbCrLf....
0
by: diff | last post by:
I am having trouble preventing a bound source from updating using event-driven validation. There is a very nice article on MSDN explaining this;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.