Click here to Skip to main content
11,715,491 members (85,660 online)
Rate this: bad
Please Sign up or sign in to vote.
User control:
on button click call java script function
javascript function
function clear() {

btn.Attributes.Add("onclick", "clear()");

on page:
i had 2 user controls on my page

on button click script doesn't work
Posted 3-Jul-12 20:29pm
Edited 3-Oct-12 3:25am
Sandeep Mewara at 4-Jul-12 2:42am
Incomplete. Posting a statement like not working will got get you any helpful answer. You need to share what code you used to access specific function and how are they wired up.

based on your question, your reference to Javascript code is not correct and need a look up.
aspnet_regiis at 4-Jul-12 2:46am
I am unable to guess what code you have written and what problem you are facing... Should we start the guessing game ?
Bryian Tan at 3-Oct-12 12:09pm
What browser you testing it on? Firefox, IE, Chrome,, etc...?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have a javacript function with same name in both the instances of user control. so on the page you actually ended up with the 2 functions with same name and this is causing the problem.

I suggest to add the controls ID after the function so that the function names are different.

Also, I think you need to write these functions from server side using RegisterClientScript for them to work.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you added Separate JavaScript File then add reference of that file to your page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 518
1 Richard MacCutchan 300
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100