OnClientClick Variable Substitution

  • Thread starter Thread starter Jennifer Mathews
  • Start date Start date
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
 
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
 
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
 
Back
Top