How to solve this " problem? Thank You.

S

Shapper

Hello,

I have an ASP:ImageButton where I want to call a function and pass a
string:

OnClick="Change_Photo("John")"

I am having problems with "".

I tried
OnClick="Change_Photo('John')"

And

OnClick="Change_Photo(''John'')"

I wasn't able to make this work.

What do I need to fix this?

Thanks,
Miguel
 
S

Sylvain Lafontaine

Well, I'm not sure about the language for which this string will be used, so
the solution is either to use two " for each embedded " or to use a backlash
\:

OnClick="Change_Photo(""John"")"

or :
OnClick="Change_Photo(\"John\")"

However, the fact that the end result might be displayed inside an HTML page
and be used as part of a Javascript or a VBScript instruction might make
things a little more complicated; so none of the above might be your
solution.
 
C

CodeMeister

I'm not sure if you're trying to run client script or have a method called
on postback.

For client script you'll need to use the following:

imgButton.Attributes.Add("onclick", "Change_Photo('John')");

If you need to handle a postback the you need to add an event handler to
your code. If you need to pass a string back, then you'll want to use the
Command event and set the CommandArgument to the value you want to be
returned during the postback.

imgButton.Command += new CommandEventHandler(img_Command);

in the event handler you can get teh value from the
CommandEventArgs.CommandArgument property.


IHTH

Jon
 
S

Shapper

Hi,

It's not that. In my HTML code I have an image button:
<asp:ImageButton id="ib" runat="server" CssClass="ib"
OnClick="Change_Photo("image01_url")" Width="56"></asp:ImageButton>

The double quotes are the problem.

In my aspx.vb code I have the function:
Public Sub Change_Photo
....
End Sub

I know I could add the OnClick event in my aspx.vb but I would like to
solve this problem in my HTML code. I would prefer to have it there.

Thanks,
Miguel
 
D

Daniel Walzenbach

Miguel,

(1) use ib.Attributes.Add("onclick", "Change_Photo('image01_url')") in the
page.load event in your aspx.vb file to register the client side function.

(2) write a client side function which will change the picture.

Greetings

Daniel
 
C

Craig Deelsnyder

Shapper said:
Hi,

It's not that. In my HTML code I have an image button:
<asp:ImageButton id="ib" runat="server" CssClass="ib"
OnClick="Change_Photo("image01_url")" Width="56"></asp:ImageButton>

The double quotes are the problem.

In my aspx.vb code I have the function:
Public Sub Change_Photo
...
End Sub

I know I could add the OnClick event in my aspx.vb but I would like to
solve this problem in my HTML code. I would prefer to have it there.

Thanks,
Miguel

The problem is that the 'event' attributes on the HTML markup of server
controls, the ones that map to an actual event on the class for that
control, define what handler method the server code will call for the
event. All you can put in there is a method name, not an actual call
with an arg, etc.

What CodeMeister was getting at was that to pass more info along to the
handler, you can use the OnCommand event/attribute instead (as well as a
couple other attributes). These can be defined in the code-front, where
you map it to a handler method you define that then looks inside the
eventArg info to see what exactly happened.

More info/examples:

http://authors.aspalliance.com/aspxtreme/aspnet/syntax/imagebuttonwebcontrol.aspx
 
H

Hans Kesting

Shapper said:
Hi,

It's not that. In my HTML code I have an image button:
<asp:ImageButton id="ib" runat="server" CssClass="ib"
OnClick="Change_Photo("image01_url")" Width="56"></asp:ImageButton>

The double quotes are the problem.

In my aspx.vb code I have the function:
Public Sub Change_Photo
...
End Sub

OK, so your OnClick is a *server side* function, that was not clear
from your other posts.

Would this work:
OnClick='Change_Photo("image01_url")'

(so: keep the double quotes around "image01_url" and use single quotes
around the whole OnClick value)

Hans Kesting
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top