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 / General / July 2007

Tip: Looking for answers? Try searching our database.

Passing <%= myControl.ClientID %> into Javascript function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 26 Jul 2007 06:02 GMT
I can successfully use <%=myControl.ClientID%> inside of a Javascript
function, but does anyone know if it is possible to pass this value to
my Javascript function? The reason I want to do this is so I can
abstract my Javascript function out of my ASP.NET user control.

Ideally, I would like to have a function like this.

function testMe(control){
  document.getElementByID(control).style = ...
  // do more useful things here
  // I am trying not to have to use this...
  // document.getElementByID('<%=btnTest.ClientID%>').style = ...
}

I would like to be able to call it like this...

<asp:LinkButton id="btnTest" runat="server" OnClientClick="return
testMe(<%=this.ClientID%>)" text="test" />

But this does not work. If I have to keep the actual control name in
the javascript file, then my decoupling is lost. Is this approach
possible?

Thanks.
Sergey Poberezovskiy - 26 Jul 2007 06:56 GMT
Alex,
why not just pass the reference to the control itself, rather than its ID:
<asp:LinkButton id="btnTest" runat="server" OnClientClick="return
testMe(this);" text="test" />

function testMe(control){
  control.style = ...
}

> I can successfully use <%=myControl.ClientID%> inside of a Javascript
> function, but does anyone know if it is possible to pass this value to
[quoted text clipped - 20 lines]
>
> Thanks.
Masudur - 26 Jul 2007 07:02 GMT
On Jul 26, 11:56 am, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.com> wrote:
> Alex,
> why not just pass the reference to the control itself, rather than its ID:
[quoted text clipped - 29 lines]
>
> > Thanks.

hi...

Sergey Poberezovskiy's suggested method is right...
in this way you dont have to think about client id...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
Alex - 27 Jul 2007 04:15 GMT
Passing in "this" did the trick. I tried that before, but for some
reason I thought I was getting the control's ID at design time, not
the actual ASP.NET client ID at run time. This works. I appreciate the
help.

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.