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

Discussion in 'ASP .Net Web Controls' started by paul.richards@shropshirefire.gov.uk, Mar 19, 2007.

  1. Guest

    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
    , Mar 19, 2007
    #1
    1. Advertising

  2. Bruno Piovan Guest

    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

    <> wrote in message
    news:...
    > 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
    >
    Bruno Piovan, Mar 19, 2007
    #2
    1. Advertising

  3. marss Guest

    wrote:
    > 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.
    marss, Mar 20, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    6,185
  2. Ben
    Replies:
    2
    Views:
    876
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,015
    Lawrence D'Oliveiro
    May 20, 2011
  4. Guest
    Replies:
    2
    Views:
    1,575
    Guest
    Oct 25, 2004
  5. Megha Vishwanath
    Replies:
    3
    Views:
    699
    Megha Vishwanath
    Jul 20, 2004
Loading...

Share This Page