button control and cancel submit

J

jbhopper

I use Attribute.Add to call a javascript function client-side from an asp:button control. The javascript function opens a window. My problem is that the submit event fires after the javascript code executes. When I view the source in "running documents" I see that the button is declared as "type=submit", even when I provide a commandName, which I thought changed a submit button into a command button. When I try to return false from the javascript function I get "return type mismatch". I've used this method successfully in user controls, but now I can't use it in a web page. Any suggestions

Thanks!
 
K

Ken Cox [Microsoft MVP]

Are you putting return false in your javascript or in the click event? Try
it this way?

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Attributes.Add("onclick", _
"doWelcome(); return false;")
End Sub

If this isn't the issue, maybe you could post the code that isn't working
and we can try again?

Ken
MVP [ASP.NET]
 

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,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top