OnClientClick Variable Substitution

J

Jennifer Mathews

I have a control in a user control:

<asp:ImageButton ID="imgPlusMinus" runat="server"
ImageUrl="~/gmbDiscussion/images/div_minus.gif" OnClientClick="<%= myVariable %>" />

I am using a variable for the OnClientClick. I have a default of:
Friend myVariable As String = "whatever();return false;"

But for some reason the html output is
onclick="&lt;%= myVariable %>"

and not "whatever();return false;" as I would have expected.

Can anyone tell me what I am doing wrong?

Thanks
 
S

Stan

I have a control in a user control:

                <asp:ImageButton ID="imgPlusMinus" runat="server"
ImageUrl="~/gmbDiscussion/images/div_minus.gif" OnClientClick="<%= myVariable %>" />

I am using a variable for the OnClientClick.  I have a default of:
Friend myVariable As String = "whatever();return false;"

But for some reason the html output is
   onclick="&lt;%= myVariable %>"

and not "whatever();return false;" as I would have expected.

Can anyone tell me what I am doing wrong?

Thanks

Hi Jennifer

<%= myVariable %>

that's ASP not ASP.NET

the two technologies are completely different.

To set the OnClientClick property of the ImageButton programmatically
in ASP.NET you need to do it in a separate script block embedded in
the page or using a codebehind source file with a statement something
like this:

imgPlusMinus.OnClientClick = "javascript: " & MyVariable

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top