CustomValidator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philip Korolev

    #1

    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

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

  • Hussein Zahran

    #2
    RE: CustomValidator

    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:
    [color=blue]
    > 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
    >
    > *************** *************** *
    >[/color]

    Comment

    • Philip Korolev

      #3
      Re: CustomValidator

      Hi Hussein.

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

      Phil
      "Hussein Zahran" <Hussein Zahran@discussi ons.microsoft.c om> wrote in message news:B6012E01-60D1-4B34-A22D-7440B48EDD58@mi crosoft.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:
      [color=blue]
      > 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
      >
      > *************** *************** *
      >[/color]

      Comment

      Working...