Button that just calls a sub (and does NOT submit the form)

P

paul.richards

Hi,

I want a button that just calls a subroutine (rather than submitting a
form). So, I have done this:

<asp:Button id="btNewNetworkProvider" text="New"
commandname="newprovider" onclick="newprovider" runat="server"/>

and:

Sub newprovider(sender As Object, e As EventArgs)
...
End Sub

However when I press the button it just submits the form. There is
already another button that does the submit and I have tried setting:

<form id="Form1" defaultbutton="btSubmit" ..

but this has changed nothing.

Regards,

Paul
 
B

Bruno Piovan

The Button control is rendered as <input type="submit"> by default, so
clicking the button will make a post, I would suggest you to to either use
Ajax to make the post "invisible" or you can add a Button and set the
OnClientClick to something like "window.open('page.aspx'); return false;",
this will popup a new window where page.aspx would call your sub and close
itself.

have a look at
http://msdn.microsoft.com/library/d...hop/author/dhtml/reference/methods/open_0.asp
if you want to make change the properties of the popup window. Remember that
some popup blockers may stops this popup from opening.

Bruno
 
M

marss

Hi,

I want a button that just calls a subroutine (rather than submitting a
form). So, I have done this:

<asp:Button id="btNewNetworkProvider" text="New"
commandname="newprovider" onclick="newprovider" runat="server"/>

and:

Sub newprovider(sender As Object, e As EventArgs)
...
End Sub

You can't execute a subrutine on the server-side without the form
submission if you use the usual ASP.Net controls. If you familiar with
javascript you can use XmlHttpRequest.
If not - here ajax.asp.net you can find some convenient controls that
utilize it.
To be honest: this contols also submit a form but they do not cause
page reloading and the submission is not visible for the user of your
site.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top