button to only execute javascript and not postback (using code behind)

  • Thread starter Marcel Balcarek
  • Start date
M

Marcel Balcarek

I want to create a button using code-behind that only executes javascript,
and does not post back to the server.

How can I do this - my ImageButton insists on posting back to the server.

Thank you
 
J

Joe

Hmmmm, you could check out the autopostback attribute or set the
autopostback property of your button to false if you are building it in a
codebehind.

Joe
 
A

alex bowers

hi,
any javascript run in the (client) onclick event of an
asp.net button will fire before any server side code, and
can prevent a postback to the server if you "return
false;" from the javascript.

alex
 
M

Marcel Balcarek

Thanks Joe, and Alex

Unfortunately, in my VB .NET the imagebutton does not have an autopostback
property / attribute.

The following works:

1) return false from the javascript call

Me.BoldImageButton.Attributes.Add("onclick",
"javascript:FormatText('testiframe', 'bold', '');return false")

2) ensure that the form does NOT have an onsubmit, as this will execute

<form id="Form1" onsubmit="return submitForm();" method="post"
runat="server"> -->

Thank you for your help.

Marcel
 
B

Bin Song

Why not just make it a simple HTML input button if you
don't need to post data back?

Bin Song
MCP
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top