Click here to Skip to main content
11,716,249 members (89,433 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 634
1 Maciej Los 385
2 Richard MacCutchan 280
3 F-ES Sitecore 245
4 OriginalGriff 175
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415

Advertise | Privacy | Mobile
Web02 | 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