473,513 Members | 2,558 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 userAlreadyExists
@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 custValUserExists_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles custValUserExists.ServerValidate

Dim cnn As New SqlConnection(connection.SQlConnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("userAlreadyExists", cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.CommandType = CommandType.StoredProcedure

cmdUserExists.Parameters.Add("@user_username", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Input

cmdUserExists.Parameters("@user_username").Value = Trim(art_username.Text)

cmdUserExists.Parameters.Add("@Valid", SqlDbType.Int).Direction = ParameterDirection.Output

cmdUserExists.ExecuteNonQuery()

'the line below is for checking the value returned on the confirmation page
Session("DBRETVAL") = cmdUserExists.Parameters("@Valid").Value

If cmdUserExists.Parameters("@Valid").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 1352
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 userAlreadyExists
@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 custValUserExists_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles custValUserExists.ServerValidate

Dim cnn As New SqlConnection(connection.SQlConnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("userAlreadyExists", cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.CommandType = CommandType.StoredProcedure

cmdUserExists.Parameters.Add("@user_username", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Input

cmdUserExists.Parameters("@user_username").Value = Trim(art_username.Text)

cmdUserExists.Parameters.Add("@Valid", SqlDbType.Int).Direction = ParameterDirection.Output

cmdUserExists.ExecuteNonQuery()

'the line below is for checking the value returned on the confirmation page
Session("DBRETVAL") = cmdUserExists.Parameters("@Valid").Value

If cmdUserExists.Parameters("@Valid").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****@discussions.microsoft.com> wrote in message news:B6**********************************@microsof t.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 userAlreadyExists
@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 custValUserExists_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles custValUserExists.ServerValidate

Dim cnn As New SqlConnection(connection.SQlConnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("userAlreadyExists", cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.CommandType = CommandType.StoredProcedure

cmdUserExists.Parameters.Add("@user_username", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Input

cmdUserExists.Parameters("@user_username").Value = Trim(art_username.Text)

cmdUserExists.Parameters.Add("@Valid", SqlDbType.Int).Direction = ParameterDirection.Output

cmdUserExists.ExecuteNonQuery()

'the line below is for checking the value returned on the confirmation page
Session("DBRETVAL") = cmdUserExists.Parameters("@Valid").Value

If cmdUserExists.Parameters("@Valid").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
2156
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...
2
2398
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...
1
1813
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...
0
3526
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...
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...
0
7260
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
7161
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...
1
7101
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
7525
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...
1
5089
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...
0
3234
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
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 ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.