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 / March 2008

Tip: Looking for answers? Try searching our database.

Adding Javascript to control in c# 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 04 Mar 2008 00:26 GMT
I used to do all my coding in single page DreamWeaver and am now using VS
2005.

I used to add onclick events to linkbuttons like so:

     lnkFullName.Attributes.Add("onclick", "findit");

<asp:LinkButton ID="lnkFullName" runat="server"
   Text='<%# Bind("DisplayedName") %>'
   CommandArgument='<%# Bind("DisplayedName") %>'
   CommandName="view" CssClass="name" />

This is also in a Repeater.

The error I get is:

The name 'lnkFullName' does not exist in the current context

How do attach the Javascript function to these linkbuttons?

Thanks,

Tom
Cowboy (Gregory A. Beamer) - 04 Mar 2008 00:35 GMT
Most likely missing a code declartion in the code behind. Did you place this
on the page in VS, which should solve that for you, or is this some of your
old code you are replacing?

Signature

Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************

| Think outside the box!

*************************************************
>I used to do all my coding in single page DreamWeaver and am now using VS
>2005.
[quoted text clipped - 19 lines]
>
> Tom
bruce barker - 04 Mar 2008 00:58 GMT
when you define a control like:

 <asp:linkbutton id="link1" runat="server">

in the aspx class, as class variable named linlk1 is defined, and in the
init code somethink like:

  link1 = new LinkButton();
  link1.ID = "link1";
  ...

is generated. when the control is in a repeater, it can not create a
vraiable for the control, because there are 0..n controls. also the control
are created at databind, not during init. the control are children of the
repeator, not the page.

the easiest way to access the controls in a repeater is to use the
OnDataBound event, and use FindControl to access the control. see any
databind examples.

-- bruce (sqlwork.com)

> I used to do all my coding in single page DreamWeaver and am now using VS
> 2005.
[quoted text clipped - 19 lines]
>
> Tom
tshad - 04 Mar 2008 01:22 GMT
> when you define a control like:
>
[quoted text clipped - 16 lines]
> OnDataBound event, and use FindControl to access the control. see any
> databind examples.

That was exactly what I had to do.  I needed to do a FindConrol then do an
".OnClientClick".

I guess you don't nee the Attributes.Add anymore.

Thanks,

Tom

> -- bruce (sqlwork.com)
>
[quoted text clipped - 21 lines]
>>
>> Tom
Mark Rae [MVP] - 04 Mar 2008 10:09 GMT
> That was exactly what I had to do.  I needed to do a FindConrol then do an
> ".OnClientClick".
>
> I guess you don't need the Attributes.Add any more.

You do for all webcontrols which don't have an OnClientClick property, which
is really only available to Button controls, and to controls which inherit
from Button controls e.g. ImageButton, LinkButton etc. It doesn't exist for
HyperLink controls, etc...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

tshad - 04 Mar 2008 19:02 GMT
>> That was exactly what I had to do.  I needed to do a FindConrol then do
>> an ".OnClientClick".
[quoted text clipped - 5 lines]
> inherit from Button controls e.g. ImageButton, LinkButton etc. It doesn't
> exist for HyperLink controls, etc...

I see.

Thanks,

Tom

Rate this thread:







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.