Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / October 2003

Tip: Looking for answers? Try searching our database.

user controls and javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dune - 01 Oct 2003 01:16 GMT
Hi there,

I have a user control and I need to carry out some client-
side custom validation on the controls within the user
control (hope that makes sense :) )

So I've stuck a CustomValidator into the page and set
ClientValidationFunction to the name of my javascript
validation function. But this is where I get lost...how
does one refer to the controls within the user control?

Referring to these internal controls using "document.forms
(0)..." seems wrong as there is no form within the user
control itself (as the user control will reside in the
form element of the web form that it is added to) and i've
tried it out and this indeed doesn't work.

So, this suggests to me that I can't carry out validation
using javascript within the user control itself, but must
instead, do the validation in the web form containing the
user control.

I have a bunch of these user controls on a web form which
is why it would be really nice to be able to make them do
their own validation, but if I have to validate them in
the web form, I guess I'll need to iterate through them
somehow?

Any suggestions?

Cheers :)
JB - 27 Oct 2003 08:14 GMT
I'm in exactly the same boat - tried various ways but my JS is not
that strong so floundering a bit.

Anyone out there lend a hand?

TIA

> Hi there,
>
[quoted text clipped - 27 lines]
>
> Cheers :)
John Saunders - 27 Oct 2003 12:45 GMT
> I'm in exactly the same boat - tried various ways but my JS is not
> that strong so floundering a bit.
>
> Anyone out there lend a hand?

Maybe this will help:
ASP.NET Validation in Depth
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm
l/aspplusvalid.asp).
Signature

John Saunders
Internet Engineer
john.saunders@surfcontrol.com

> > Hi there,
> >
[quoted text clipped - 27 lines]
> >
> > Cheers :)
Rasmus Rummel - 27 Oct 2003 13:44 GMT
Hi Dune

Your UserControl will have a property UniqueID and all Controls on that
UserControl (residing in you UserControl Controls collection) will have
properties like ClientID and UniqueID. Lets say you have a Textbox
WebControl on your UserControl and you give the textbox an ID="tbNested"
then your Textbox ClientID is also "tbNested", but your Textbox UniqueID is
your UserControl UniqueID concatenated with the TextBox ClientID, so in your
UserControl, the following will be true:
tbNested.UniqueID = this.UniqueID + tbNested.ClientID (=this.UniqueID +
"tbNested").
ASP.NET will automatically give your Textbox an Id-attribute in the html
stream and the value is exactly the UniqueID, this means you have a unique
reference to your Textbox on the client side. The Javascript must be emitted
from your UserControl, because it is in your UserControl you know the
UniqueID of your Textbox.

To emit javascript from a UserControl use eg. the
Page.RegisterClientScriptBlock("key", "[javascript]"), you can look
RegisterClientScriptBlock up in your .NET Documentation or on MSDN online.
Then you first get the grip of it, it is straightforward to connect
javascript with your controls through the UniqueID (however there are some
potential complicated problem with the Id-separator, if you run into that,
check out a Control id-separator and id-render-separator in the debugger -
rember to follow the hierarchy all the way up to Control).

Regards
Rasmus Rummel
www.menulab.com

> Hi there,
>
[quoted text clipped - 27 lines]
>
> Cheers :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.