Click here to Skip to main content
11,934,809 members (49,205 online)
Rate this:
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 21:29pm
Edited 3-Oct-12 4:25am
Sandeep Mewara 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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.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