Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using Javascript in UserControl

Reply
Thread Tools

Using Javascript in UserControl

 
 
Lau Lei Cheong
Guest
Posts: n/a
 
      05-20-2004
Hello,

I'm writing a usercontrol to be included in my project. The usercontrol
have a few javascript function to do the client-side tasks. However, the
controls on the usercontrol seems to change at execution(e,g: the TextBox
with id & name"txtbox" in usercontrol "folder1" will have name
"folder1:txtbox" and id "folder1_txtbox" during execution)
Since I'll use the control in many place inside my project, it's not
possible for me to hardcode their name. Could anyone suggest some way to
address the controls?
The first idea come up in my mind is to use document.getElementById().
But then I do not know how to gather the ID of the usercontrol itself.
Any help would be appreciated. Thank you.

Regards,
Lau Lei Cheong


 
Reply With Quote
 
 
 
 
Darren Clark
Guest
Posts: n/a
 
      05-20-2004
If you want to konw the exact name of the controll that gets sent out in the
HTML

use the ClientID propertiy.

it will return the folder1_txtBox value for you .

"Lau Lei Cheong" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hello,
>
> I'm writing a usercontrol to be included in my project. The

usercontrol
> have a few javascript function to do the client-side tasks. However, the
> controls on the usercontrol seems to change at execution(e,g: the TextBox
> with id & name"txtbox" in usercontrol "folder1" will have name
> "folder1:txtbox" and id "folder1_txtbox" during execution)
> Since I'll use the control in many place inside my project, it's not
> possible for me to hardcode their name. Could anyone suggest some way to
> address the controls?
> The first idea come up in my mind is to use document.getElementById().
> But then I do not know how to gather the ID of the usercontrol itself.
> Any help would be appreciated. Thank you.
>
> Regards,
> Lau Lei Cheong
>
>



 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      05-20-2004
You can read up on the subject in this article:

http://www.aspnetpro.com/features/20...200406so_f.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


"Lau Lei Cheong" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hello,
>
> I'm writing a usercontrol to be included in my project. The

usercontrol
> have a few javascript function to do the client-side tasks. However, the
> controls on the usercontrol seems to change at execution(e,g: the TextBox
> with id & name"txtbox" in usercontrol "folder1" will have name
> "folder1:txtbox" and id "folder1_txtbox" during execution)
> Since I'll use the control in many place inside my project, it's not
> possible for me to hardcode their name. Could anyone suggest some way to
> address the controls?
> The first idea come up in my mind is to use document.getElementById().
> But then I do not know how to gather the ID of the usercontrol itself.
> Any help would be appreciated. Thank you.
>
> Regards,
> Lau Lei Cheong
>
>



 
Reply With Quote
 
Lau Lei Cheong
Guest
Posts: n/a
 
      05-20-2004
Oops, I do not have an account to login there.

Thank you anyway.

"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> 在郵件
news:%23$(E-Mail Removed) 中撰寫...
> You can read up on the subject in this article:
>
> http://www.aspnetpro.com/features/20...200406so_f.asp
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
> "Lau Lei Cheong" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hello,
> >
> > I'm writing a usercontrol to be included in my project. The

> usercontrol
> > have a few javascript function to do the client-side tasks. However, the
> > controls on the usercontrol seems to change at execution(e,g: the

TextBox
> > with id & name"txtbox" in usercontrol "folder1" will have name
> > "folder1:txtbox" and id "folder1_txtbox" during execution)
> > Since I'll use the control in many place inside my project, it's not
> > possible for me to hardcode their name. Could anyone suggest some way to
> > address the controls?
> > The first idea come up in my mind is to use

document.getElementById().
> > But then I do not know how to gather the ID of the usercontrol itself.
> > Any help would be appreciated. Thank you.
> >
> > Regards,
> > Lau Lei Cheong
> >
> >

>
>



 
Reply With Quote
 
Lau Lei Cheong
Guest
Posts: n/a
 
      05-20-2004
I'll do more experiments on that. Thank you.

"Darren Clark" <(E-Mail Removed)> 在郵件
news:(E-Mail Removed) 中撰寫...
> If you want to konw the exact name of the controll that gets sent out in

the
> HTML
>
> use the ClientID propertiy.
>
> it will return the folder1_txtBox value for you .



 
Reply With Quote
 
Lau Lei Cheong
Guest
Posts: n/a
 
      05-21-2004
After some experiment, I finally come up with this piece of code.
Not using ClientID, but it does do the job.

var ctlname = name.substr(0, name.search(/:/i));
document.getElementById(ctlname + 'mycontrol').value='newvalue';

I use name property instead of Id to address the control because colon
is not commonly used in name, while underscore in Id does commonly used
in Id.

Regards,
Lau Lei Cheong

"Lau Lei Cheong" <(E-Mail Removed)> 在郵件
news:(E-Mail Removed) 中撰寫...
> I'll do more experiments on that. Thank you.
>
> "Darren Clark" <(E-Mail Removed)> 在郵件
> news:(E-Mail Removed) 中撰寫...
> > If you want to konw the exact name of the controll that gets sent out in

> the
> > HTML
> >
> > use the ClientID propertiy.
> >
> > it will return the folder1_txtBox value for you .

>
>



 
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
TabStrip/Multipage using UserControl (.ascx) contained within a UserControl(.ascx) shaileenpatel@yahoo.com ASP .Net Web Controls 2 05-03-2005 05:01 PM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments