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

  • Thread starter Thread starter Marcel Balcarek
  • Start date 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
 
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
 
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
 
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
 
Why not just make it a simple HTML input button if you
don't need to post data back?

Bin Song
MCP
 
Back
Top