By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

How to solve this " problem? Thank You.

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #2

P: n/a
Hi,

None of that worked.

Does anyone else know how to solve this?

Thanks,
Miguel

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:sylvain aei ca (fill the blanks, no spam please):
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.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #3

P: n/a
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

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

None of that worked.

Does anyone else know how to solve this?

Thanks,
Miguel

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:sylvain aei ca (fill the blanks, no spam please):
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.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
> 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
>

Nov 19 '05 #4

P: n/a
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

"CodeMeister" <jw********@codemeister.net> wrote in message
news:jw********@codemeister.net:
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

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

None of that worked.

Does anyone else know how to solve this?

Thanks,
Miguel

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:sylvain aei ca (fill the blanks, no spam please):

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.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
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
>



Nov 19 '05 #5

P: n/a
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
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> schrieb im Newsbeitrag
news:uN*************@TK2MSFTNGP12.phx.gbl...
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

"CodeMeister" <jw********@codemeister.net> wrote in message
news:jw********@codemeister.net:
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

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> None of that worked.
>
> Does anyone else know how to solve this?
>
> Thanks,
> Miguel
>
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:sylvain aei ca (fill the blanks, no spam please):
>

>> 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.
>>
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Technologies Virtual-PC
>> E-mail: http://cerbermail.com/?QugbLEWINF
>>
>>
>> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
>> news:O5**************@TK2MSFTNGP09.phx.gbl...
>>

>> > 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
>> >

>

Nov 19 '05 #6

P: n/a
Shapper wrote:
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/aspxt...ebcontrol.aspx

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #7

P: n/a
Shapper wrote:
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
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.