Custom Client-Side Validation in Web User Control

Discussion in 'ASP .Net Building Controls' started by Stuart Whiteford, Feb 22, 2004.

  1. Guys,

    I have a custom validator that has the default property ControlToValidate
    plus one called SecondControlToValidate that I have created, like so...

    <ows:eitherorvalidator id="eovNumberName" runat="server"
    ControlToValidate="txtNumber" SecondControlToValidate="txtName"
    EnableClientScript="True"></ows:eitherorvalidator>

    ....in my Validator Class I have the following...

    Protected eitherOrSecondControlToValidate As String

    Public Property SecondControlToValidate() As String
    Get
    Return eitherOrSecondControlToValidate
    End Get
    Set(ByVal Value As String)
    eitherOrSecondControlToValidate = Value
    End Set
    End Property

    Protected Overrides Sub AddAttributesToRender(ByVal writer As
    HtmlTextWriter)
    If (Me.DetermineRenderUplevel And Me.EnableClientScript) Then
    MyBase.AddAttributesToRender(writer)
    writer.AddAttribute("secondcontroltovalidate",
    Me.SecondControlToValidate)
    End If
    End Sub

    All this works fine when the textboxes and validator is straight on the
    page, but I can't get it working in a Web User Control. I know about
    UniqueID and ClientID but what I don't know is how get the ClientID from the
    string being passed in so I can use it in the AddAttributesToRender Sub (or
    should I be passing in a Control instead).

    Mucho head scratching.

    TIA,
    Stuart.
    Stuart Whiteford, Feb 22, 2004
    #1
    1. Advertising

  2. Peter,

    Managed to get this working.

    Thanks,
    Stuart.


    "Peter Blum" <> wrote in message
    news:eljXjmm%...
    > When providing a control's ID to the client side, always use the ClientID
    > property as it is the value represented in the id= attribute of the HTML
    > generated. Use FindControl() to get the control itself.
    >
    > Dim vOtherControl =
    > Me.NamingContainer.FindControl(Me.SecondControlToValidate) ' this will
    > throw an exception if not found. So use Try..Catch
    > writer.AddAttribute("secondcontroltovalidate", vOtherControl.ClientID)
    >
    > --- Peter Blum
    > www.PeterBlum.com
    > Email:
    > Creator of "Professional Validation And More" at
    > http://www.peterblum.com/vam/home.aspx
    >
    > "Stuart Whiteford" <> wrote in

    message
    > news:uECBI%23V%...
    > > Guys,
    > >
    > > I have a custom validator that has the default property

    ControlToValidate
    > > plus one called SecondControlToValidate that I have created, like so...
    > >
    > > <ows:eitherorvalidator id="eovNumberName" runat="server"
    > > ControlToValidate="txtNumber" SecondControlToValidate="txtName"
    > > EnableClientScript="True"></ows:eitherorvalidator>
    > >
    > > ...in my Validator Class I have the following...
    > >
    > > Protected eitherOrSecondControlToValidate As String
    > >
    > > Public Property SecondControlToValidate() As String
    > > Get
    > > Return eitherOrSecondControlToValidate
    > > End Get
    > > Set(ByVal Value As String)
    > > eitherOrSecondControlToValidate = Value
    > > End Set
    > > End Property
    > >
    > > Protected Overrides Sub AddAttributesToRender(ByVal writer As
    > > HtmlTextWriter)
    > > If (Me.DetermineRenderUplevel And Me.EnableClientScript) Then
    > > MyBase.AddAttributesToRender(writer)
    > > writer.AddAttribute("secondcontroltovalidate",
    > > Me.SecondControlToValidate)
    > > End If
    > > End Sub
    > >
    > > All this works fine when the textboxes and validator is straight on the
    > > page, but I can't get it working in a Web User Control. I know about
    > > UniqueID and ClientID but what I don't know is how get the ClientID from

    > the
    > > string being passed in so I can use it in the AddAttributesToRender Sub

    > (or
    > > should I be passing in a Control instead).
    > >
    > > Mucho head scratching.
    > >
    > > TIA,
    > > Stuart.
    > >
    > >

    >
    >
    Stuart Whiteford, Feb 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,096
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    748
    Kevin Spencer
    Jun 2, 2005
  3. Boss302
    Replies:
    0
    Views:
    1,041
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    649
    Bogdan
    Jun 9, 2008
  5. Zoe Hart
    Replies:
    1
    Views:
    366
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page