Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
User control:
on button click call java script function
javascript function
JavaScript
function clear() {
    alert('test');
}

and

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


on page:
i had 2 user controls on my page

problem:
on button click script doesn't work
Posted
Updated 3-Oct-12 3:25am
v3
Comments
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.
bbirajdar 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...?

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.
 
Share this answer
 
v2
If you added Separate JavaScript File then add reference of that file to your page.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900