Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
User control:
on button click call java script function
javascript function
function clear() {
    alert('test');
}
and
 
btn.Attributes.Add("onclick", "clear()");
 
on page:
i had 2 user controls on my page
 
problem:
on button click script doesn't work
Posted 3-Jul-12 21:29pm
Edited 3-Oct-12 4:25am
_Amy51.5K
v3
Comments
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
good
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.
  Permalink  
v2
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
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