473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Validator checking for dulicates in database from gridview

Hello,
I have been trying to get a duplicate field checker to work within my
gridview using a custom validator. However with the code I have I am getting
an error

error: Object reference not set to an instance of an object

here is my code:
Protected Sub CustomValidator 1_ServerValidat e1(ByVal source As Object,
ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args)

' this code is to check for dulicates

Dim result As New Object
Dim result1 As New Object

result = CType(gvAssigne dZones.FindCont rol("TextBox3") , TextBox).Text

If args.Value = result Then
args.IsValid = True
Else
Dim db As New SchedulesTableA dapters.SelectN amedZonesTableA dapter

result1 = db.SelectDupZon e(args.Value)

If Not IsNothing(resul t) Then
args.IsValid = False
Else
args.IsValid = True
End If
End If
End Sub

where I get the error is on this line

result = CType(gvAssigne dZones.FindCont rol("Label3"), Label).Text

What I am trying to do is fisrt check to see if the text in the edit mode is
the same as the text in the item template that way the database check will
not happen and should go straight to update.

If the text is different I want to make the database call and check to see
if there is a result. If so then the update should not accur and the error
message will show instead. other wise the update takes place.

I have this kind of code working for none gridview updates. It seems to get
a bit tricky with this control "gridview" and assigning / finding the correct
values.

Any help or insite would be great.

P.S. I am using strongly typed datasets.

Thanks,
Hawk

Feb 22 '07 #1
1 1876
Just a note

I made a typo on this line: If Not IsNothing(resul t) Then

the correct code is: If Not IsNothing(resul t1) Then

Thanks Hawk

"Hawk" wrote:
Hello,
I have been trying to get a duplicate field checker to work within my
gridview using a custom validator. However with the code I have I am getting
an error

error: Object reference not set to an instance of an object

here is my code:
Protected Sub CustomValidator 1_ServerValidat e1(ByVal source As Object,
ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args)

' this code is to check for dulicates

Dim result As New Object
Dim result1 As New Object

result = CType(gvAssigne dZones.FindCont rol("TextBox3") , TextBox).Text

If args.Value = result Then
args.IsValid = True
Else
Dim db As New SchedulesTableA dapters.SelectN amedZonesTableA dapter

result1 = db.SelectDupZon e(args.Value)

If Not IsNothing(resul t) Then
args.IsValid = False
Else
args.IsValid = True
End If
End If
End Sub

where I get the error is on this line

result = CType(gvAssigne dZones.FindCont rol("Label3"), Label).Text

What I am trying to do is fisrt check to see if the text in the edit mode is
the same as the text in the item template that way the database check will
not happen and should go straight to update.

If the text is different I want to make the database call and check to see
if there is a result. If so then the update should not accur and the error
message will show instead. other wise the update takes place.

I have this kind of code working for none gridview updates. It seems to get
a bit tricky with this control "gridview" and assigning / finding the correct
values.

Any help or insite would be great.

P.S. I am using strongly typed datasets.

Thanks,
Hawk
Feb 22 '07 #2

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

Similar topics

2
263
by: Mike P | last post by:
Why do the validation server controls behave differently on my live site from on my local development machine? I have several text boxes that are validated by Required Validators and a couple of Regular Expression Validators, and then I have a Custom Validator which I use to check for a valid email address and database stuff. On my local machine, the validation works by first checking if the Required and Regular Expression Validators...
9
5166
by: Alex Shirley | last post by:
Hi there I’m simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I have other code within the customvalidator which works). This won’t work (within servervalidate): If txtBox.Text.ToString = "" Then raise exception…..
8
7837
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
0
1679
by: Khuzema | last post by:
Dear All, I am using issue tracker architecture and developed business object for my application. Now, in VS Beta 2, I humbly want to know how i can have same feature as dataset, in my business object, what i mean is, if you have dataset object and assign it to gridview, you can add/edit/delete row (without affecting table) and then post it back to database. Same thing i want to have for my business object (which is generic collection)...
8
5042
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
2
8992
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User object (custom class) is created, and properties are populated in each step of the wizard. In one of the steps, the User is assigned to 1 or more Programs. Assigned Programs are stored by the User object in a List, and displayed in a GridView in the...
4
6881
by: kpg | last post by:
I can't get the CustomValidator (CV) ErrorMessage to display in the ValidationSummary. On the same page I have several RequiredField Validators and a Range Validator, that all work just fine, that is, the ErrorMessage text is displayed by the Validation summary control. If I leave the CV Text field blank then the errormmessage does display on the CV itself.
3
3539
by: Rich Squid | last post by:
Hello Here's my basic problem: On my asp.net form page I have a DetailsView (default mode=edit) bound to a AccessDataSource control. Users can successfuly update a databound template field, but I wanted to add a custom validator to check that the account number they are entering exists in a table in the Access Database.
5
1280
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= | last post by:
Created a Custom Validation Ctrl in EW2 to validate a text box entry. Want to make sure entry is evenly divisible by 7, and that value is not 0. However, args.IsValid = false, even if 77 is entered in text box. Tag and script that were added to page follow: <asp:CustomValidator id="CustomValidator1" runat="server" ClientValidationFunction="ClientValidateSerial3" ControlToValidate="SerialNumber3" Display="Dynamic" ErrorMessage="Entry...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.