473,587 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CustomValidator

Hi All. Tore most of my hair out trying to solve this already! Please allow me to keep the remaining two :-)

What I am trying to do is use customValidator to go to a database via a stored procedure and fish out a UserName value. If it finds it, I want it to return 1 and if not I want it to return 0. On the ASP.NET page I have a field called user_username that customValidator is pointing to as a control to validate. The subroutine for the validator and my stored procedure are below. I now have 37 instances of the username = pkorolev and I get 37 as the value returned by the stored procedure, however the point where I want the validator to invalidate the page, the code fails. So, I get a correct value returned by the database (Enterprise Manager test), I get this value correctly on the ASPX page as output but the IsValid bit fails. What am I missing, seetings perhaps???? I bet it is something really simple.
*************** ********
create procedure userAlreadyExis ts
@user_username nvarchar(100),
@valid int output
as
declare @userValid int

select @userValid = Count(*) from user_pass
where user_username = @user_username
set @Valid = convert(int, @userValid) -- in this line i am simply trying to ensure that value coming back as an iteger
*************** *******
CustomValidator SUB:

*************** ******
Private Sub custValUserExis ts_ServerValida te(ByVal source As System.Object, ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles custValUserExis ts.ServerValida te

Dim cnn As New SqlConnection(c onnection.SQlCo nnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("use rAlreadyExists" , cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.C ommandType = CommandType.Sto redProcedure

cmdUserExists.P arameters.Add(" @user_username" , SqlDbType.NVarC har, 100).Direction = ParameterDirect ion.Input

cmdUserExists.P arameters("@use r_username").Va lue = Trim(art_userna me.Text)

cmdUserExists.P arameters.Add(" @Valid", SqlDbType.Int). Direction = ParameterDirect ion.Output

cmdUserExists.E xecuteNonQuery( )

'the line below is for checking the value returned on the confirmation page
Session("DBRETV AL") = cmdUserExists.P arameters("@Val id").Value

If cmdUserExists.P arameters("@Val id").Value = 0 Then

args.IsValid = True

Else

args.IsValid = False

End If

Catch ex As Exception

lbltype.Text = ex.ToString

End Try

End Sub

*************** *************** *

Jul 21 '05 #1
2 1359
Hi Philip
what is the value of the @valid parameter when you debug your page could
you please debug and see if it will enter the if statement correctly

"Philip Korolev" wrote:
Hi All. Tore most of my hair out trying to solve this already! Please allow me to keep the remaining two :-)

What I am trying to do is use customValidator to go to a database via a stored procedure and fish out a UserName value. If it finds it, I want it to return 1 and if not I want it to return 0. On the ASP.NET page I have a field called user_username that customValidator is pointing to as a control to validate. The subroutine for the validator and my stored procedure are below. I now have 37 instances of the username = pkorolev and I get 37 as the value returned by the stored procedure, however the point where I want the validator to invalidate the page, the code fails. So, I get a correct value returned by the database (Enterprise Manager test), I get this value correctly on the ASPX page as output but the IsValid bit fails. What am I missing, seetings perhaps???? I bet it is something really simple.
*************** ********
create procedure userAlreadyExis ts
@user_username nvarchar(100),
@valid int output
as
declare @userValid int

select @userValid = Count(*) from user_pass
where user_username = @user_username
set @Valid = convert(int, @userValid) -- in this line i am simply trying to ensure that value coming back as an iteger
*************** *******
CustomValidator SUB:

*************** ******
Private Sub custValUserExis ts_ServerValida te(ByVal source As System.Object, ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles custValUserExis ts.ServerValida te

Dim cnn As New SqlConnection(c onnection.SQlCo nnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("use rAlreadyExists" , cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.C ommandType = CommandType.Sto redProcedure

cmdUserExists.P arameters.Add(" @user_username" , SqlDbType.NVarC har, 100).Direction = ParameterDirect ion.Input

cmdUserExists.P arameters("@use r_username").Va lue = Trim(art_userna me.Text)

cmdUserExists.P arameters.Add(" @Valid", SqlDbType.Int). Direction = ParameterDirect ion.Output

cmdUserExists.E xecuteNonQuery( )

'the line below is for checking the value returned on the confirmation page
Session("DBRETV AL") = cmdUserExists.P arameters("@Val id").Value

If cmdUserExists.P arameters("@Val id").Value = 0 Then

args.IsValid = True

Else

args.IsValid = False

End If

Catch ex As Exception

lbltype.Text = ex.ToString

End Try

End Sub

*************** *************** *

Jul 21 '05 #2
Hi Hussein.

Thanks for the reply. @Valid = 46. There are 46 instances of pkorolev which successfully made it though :-(

Phil
"Hussein Zahran" <Hussein Za****@discussi ons.microsoft.c om> wrote in message news:B6******** *************** ***********@mic rosoft.com...
Hi Philip
what is the value of the @valid parameter when you debug your page could
you please debug and see if it will enter the if statement correctly

"Philip Korolev" wrote:
Hi All. Tore most of my hair out trying to solve this already! Please allow me to keep the remaining two :-)

What I am trying to do is use customValidator to go to a database via a stored procedure and fish out a UserName value. If it finds it, I want it to return 1 and if not I want it to return 0. On the ASP.NET page I have a field called user_username that customValidator is pointing to as a control to validate. The subroutine for the validator and my stored procedure are below. I now have 37 instances of the username = pkorolev and I get 37 as the value returned by the stored procedure, however the point where I want the validator to invalidate the page, the code fails. So, I get a correct value returned by the database (Enterprise Manager test), I get this value correctly on the ASPX page as output but the IsValid bit fails. What am I missing, seetings perhaps???? I bet it is something really simple.
*************** ********
create procedure userAlreadyExis ts
@user_username nvarchar(100),
@valid int output
as
declare @userValid int

select @userValid = Count(*) from user_pass
where user_username = @user_username


set @Valid = convert(int, @userValid) -- in this line i am simply trying to ensure that value coming back as an iteger


*************** *******


CustomValidator SUB:



*************** ******


Private Sub custValUserExis ts_ServerValida te(ByVal source As System.Object, ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args) Handles custValUserExis ts.ServerValida te

Dim cnn As New SqlConnection(c onnection.SQlCo nnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("use rAlreadyExists" , cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.C ommandType = CommandType.Sto redProcedure

cmdUserExists.P arameters.Add(" @user_username" , SqlDbType.NVarC har, 100).Direction = ParameterDirect ion.Input

cmdUserExists.P arameters("@use r_username").Va lue = Trim(art_userna me.Text)

cmdUserExists.P arameters.Add(" @Valid", SqlDbType.Int). Direction = ParameterDirect ion.Output

cmdUserExists.E xecuteNonQuery( )

'the line below is for checking the value returned on the confirmation page
Session("DBRETV AL") = cmdUserExists.P arameters("@Val id").Value

If cmdUserExists.P arameters("@Val id").Value = 0 Then

args.IsValid = True

Else

args.IsValid = False

End If

Catch ex As Exception

lbltype.Text = ex.ToString

End Try

End Sub

*************** *************** *

Jul 21 '05 #3

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

Similar topics

7
2169
by: jcpmeticulus | last post by:
Hi I've spent the last day or so debugging a problem with a CustomValidator and am now totally stumped! Basically I use a number of CustomValidator's on my page, but have cut this down now to only 2. When the page is first loaded the CustomValidator are made and the generated HTML contains both of them. When the "Apply" button is clicked...
2
2406
by: Stephen Miller | last post by:
Can the CustomValidator be used to simply report unexpected errors, without requiring Client/Server validation? To explain, say you had a simple text box and button that did a Full-text Search of a Catalogue in SQL. Malformed search requests can generate a variety of errors, which I simply want to catch, set the CustomValidator's IsValid...
1
1817
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in ValidationSummary. Now I want to check the username should contain only chatacters, ( I want to use customvalidator), when i enter char+number it trap the event...
0
3534
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 OnServerValidate property of the customvalidator 3. Get reference to the Data Item object (For DataList is DataListItem, for DataGrid its...
7
402
by: jcpmeticulus | last post by:
Hi I've spent the last day or so debugging a problem with a CustomValidator and am now totally stumped! Basically I use a number of CustomValidator's on my page, but have cut this down now to only 2. When the page is first loaded the CustomValidator are made and the generated HTML contains both of them. When the "Apply" button is clicked...
0
7923
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...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
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...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
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...
1
5719
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
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...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.