Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a label in aspx page and i am setting its text from code-behind as :

label.text= "<image  önclick='javascript:show('" + imagename + "')'/>";


And i am having JavaScript defined in my master page as
<script type=javascript>

    function show(image) {
alert(image);
}
</script>

But then it gives me runtime error and JavaScript isn't called.

Can someone tell me how can i solve this.
Posted
Updated 4-Feb-11 0:49am
v2
Comments
TweakBird 4-Feb-11 6:50am    
Edited for formatting. Please use <pre> tag for code blocks.
mandarapu 4-Feb-11 6:59am    
y the using of label and declaring image in it.u can take that image control directly.

Try it this way:
C#
label.Text= "<image  onclick=\"javascript:show('" + imagename + "')\"/>";


There was an ö in onclick and the quotes in java script were messed up to. The text property of the label starts with a capital t. Besides that you shouldn't abuse a label to ouput an image tag. You could use an asp:literal tag for that or just use an image tag because that's what it was meant for.

Hope that helps.

Cheers!
 
Share this answer
 
v3
Comments
Espen Harlinn 4-Feb-11 11:31am    
5+, nicely spotted :)
 
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