link button client csript

S

Simon

I have linkButton:
<asp:LinkButton ID="lnkAddMedia" runat="server" CausesValidation="false"
Text="ADD media"></asp:LinkButton>

In code behind file(c#) I add a client script to this link button:
lnkAddMedia.OnClientClick="vbscript:selectMedia('1')";

When page is rendered, the rendered code is:

<a onclick="vbscript:selectMedia('1');"
id="ctl00_ContentPlaceHolder1_lnkAddMedia"
href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$lnkAddMedia','')">ADD
media</a>

and I get script error message on the page:
error: Expected end of statement

I guess that error is because of semicolon, which is added to my script:
vbscript:selectMedia('1');
(vbSCript doesn't have semicolons).

This semi colon was added automatically. How can I remove that?

One way is to put javascript instead of vbscript, but I preffer programming
in vbscript, because I have all program written in this language.


Thank you for your answers,
Simon
 
C

cbDevelopment

Why not use:

lnkaddmedia.attributes.add("onclick","vbscript:selectMedia(1)")

That shouldn't do any special formatting.

----
700cb Development, Inc.
http://www.700cb.net
..NET utilities, developer tools,
and enterprise solutions

I have linkButton:
<asp:LinkButton ID="lnkAddMedia" runat="server"
CausesValidation="false" Text="ADD media"></asp:LinkButton>

In code behind file(c#) I add a client script to this link button:
lnkAddMedia.OnClientClick="vbscript:selectMedia('1')";

When page is rendered, the rendered code is:

<a onclick="vbscript:selectMedia('1');"
id="ctl00_ContentPlaceHolder1_lnkAddMedia"
href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$lnkAddMedia','
')">ADD media</a>

and I get script error message on the page:
error: Expected end of statement

I guess that error is because of semicolon, which is added to my
script: vbscript:selectMedia('1');
(vbSCript doesn't have semicolons).

This semi colon was added automatically. How can I remove that?

One way is to put javascript instead of vbscript, but I preffer
programming in vbscript, because I have all program written in this
language.


Thank you for your answers,
Simon



--
 
S

SimonZ

Hi,

"lnkaddmedia.attributes.add" is obsolete - that is massage given by new
visual studio 2005.

So I use "lnkAddMedia.OnClientClick" - that is recomended method by VS2005.

But no matter which method I use, I always get the semicolon when the page
is rendered.

I don't know why?

So I rewrite my function to javascript but still I would like to know the
reason.

I have the latest Visual studio 2005 version: 8.0.50727.42, asp.net version:
2.0.50727 and project is in C# language.

Any idea?

Regards,S
 
Joined
Mar 20, 2007
Messages
1
Reaction score
0
Answer to your question.

It may be obsolete but use
lnkaddmedia.attributes.add(" onclick","vbscript:selectMedia(1)")

or

lnkaddmedia.attributes.add(" onclick","selectMedia(1)")

Note the space before the onclick. The space should prevent VS from recognizing the attribute of onclick, and therefore not preprocess it. (Add the semicolon)

My only wish is that Microsoft used it's own products :laugh:

FYI: I am using
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727
 
Last edited:

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top