Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Stuart Whiteford #1
Custom Client-Side Validation in Web User Control
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 Guest
-
custom web control +client-side javascript + postback
Hello, I am trying to create a new Web Control (ASP.NET 1.1) that contains among other textboxes. The content of these textboxes (runat=server)... -
Can client-side script be included in a user control (ascx)?
I am creating a simple usercontrol (.ascx). There is some client-side functionality I would like it to have. I tried adding in a Script element,... -
how can i add client side javascript to a web user control?
hi, i have a web user control that i wish to add some client-side javascript to. something like this: onChange="javascript:DoSomething();" ... -
validation summary doesnt display when there's client-side validation
I have a custom validator that validates a numeric field, txtField, that allows for thousand separators. I also placed a validation summary so... -
only custom validation control does server side validation?
On a CustomValidator you have to provide the validation code because otherwise it doesn't know what to do for the validation. Other validator... -
Peter Blum #2
Re: Custom Client-Side Validation in Web User Control
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
[url]www.PeterBlum.com[/url]
Email: [email]PLBlum@PeterBlum.com[/email]
Creator of "Professional Validation And More" at
[url]http://www.peterblum.com/vam/home.aspx[/url]
"Stuart Whiteford" <stuart-nospam-whiteford@firenet.uk.com> wrote in message
news:uECBI%23V%23DHA.2180@TK2MSFTNGP09.phx.gbl...the> 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(or> string being passed in so I can use it in the AddAttributesToRender Sub> should I be passing in a Control instead).
>
> Mucho head scratching.
>
> TIA,
> Stuart.
>
>
Peter Blum Guest
-
Stuart Whiteford #3
Re: Custom Client-Side Validation in Web User Control
Peter,
Managed to get this working.
Thanks,
Stuart.
"Peter Blum" <PLBlum@Blum.info> wrote in message
news:eljXjmm%23DHA.2512@TK2MSFTNGP11.phx.gbl...message> 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
> [url]www.PeterBlum.com[/url]
> Email: [email]PLBlum@PeterBlum.com[/email]
> Creator of "Professional Validation And More" at
> [url]http://www.peterblum.com/vam/home.aspx[/url]
>
> "Stuart Whiteford" <stuart-nospam-whiteford@firenet.uk.com> wrote inControlToValidate> news:uECBI%23V%23DHA.2180@TK2MSFTNGP09.phx.gbl...> > Guys,
> >
> > I have a custom validator that has the default property> the> > 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> (or> > string being passed in so I can use it in the AddAttributesToRender Sub>> > should I be passing in a Control instead).
> >
> > Mucho head scratching.
> >
> > TIA,
> > Stuart.
> >
> >
>
Stuart Whiteford Guest



Reply With Quote

