Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass my dynamic value to a javascript function from an imagebutton onclientclick event. It works fine if I pass the static value like this
HTML
<asp:ImageButton ImageUrl="~/Images/control_play_blue.png" ForeColor="Transparent"
                        BorderStyle="None" ToolTip="Chat" runat="server" ID="btnChat" 
                        OnClientClick="javascript:return openWindow('1')" />

However it doesn't work if I try to pass dynamic values as below.

HTML
<asp:ImageButton ImageUrl="~/Images/control_play_blue.png" ForeColor="Transparent" BorderStyle="None" ToolTip="Chat" runat="server" ID="btnChat"
                        OnClientClick="javascript:return openWindow('"+<%#Eval("PujaType") %>+"')" />



I tried all possible combinations however it says tag is not well formatted. Can anyone help on this?
Posted
Comments
sudevsu 26-Mar-15 16:37pm    
Try this. May be you missed a semicolon at end
('"+<%#Eval("PujaType") %>+"');

Also I don't think you need to mention JavaScript there.
Just give OnclientClick="return function(('"+<%#Eval("PujaType") %>+"');"
nikhil choudhry 26-Mar-15 22:14pm    
No, it still says "The server tag is not well formed."
sudevsu 26-Mar-15 16:44pm    
OnClientClick="<%# "javascript:openwindow('" + Eval("PujaType") +"')" %>"

This Should work. It works for me. Let me know if it doesn't
nikhil choudhry 26-Mar-15 22:14pm    
No, it still says "The server tag is not well formed."

1 solution

I don't think you need the + signs. <%= goes into the template.
javascript:return openWindow('<%#Eval("PujaType") %>')
 
Share this answer
 
Comments
nikhil choudhry 28-Mar-15 11:03am    
No, it also doesn't work.
Sebastiaan Meijerink 28-Mar-15 11:15am    
After the page has rendered. Right click on the button and say "inspect element" (or at least in chrome it's called that.

What does the rendered HTML look like?

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