Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Custom Client-Side Validation in Web User Control

Reply
Thread Tools

Custom Client-Side Validation in Web User Control

 
 
Stuart Whiteford
Guest
Posts: n/a
 
      02-22-2004
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.


 
Reply With Quote
 
 
 
 
Stuart Whiteford
Guest
Posts: n/a
 
      02-26-2004
Peter,

Managed to get this working.

Thanks,
Stuart.


"Peter Blum" <(E-Mail Removed)> wrote in message
news:eljXjmm%(E-Mail Removed)...
> 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.SecondControlToV alidate) ' this will
> throw an exception if not found. So use Try..Catch
> writer.AddAttribute("secondcontroltovalidate", vOtherControl.ClientID)
>
> --- Peter Blum
> www.PeterBlum.com
> Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
>
> "Stuart Whiteford" <(E-Mail Removed)> wrote in

message
> news:uECBI%23V%(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom validation on a control in a user control.(asp.net 2.0) Jens Jensen ASP .Net 0 07-07-2006 09:46 AM
Web user control - custom web control - java script. Leyla ASP .Net Web Controls 0 05-01-2006 10:05 PM
Using Summary Validation control with server Custom validation =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= ASP .Net 2 10-15-2004 06:15 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments