Pinchy Pinchy - 1 year ago 232
ASP.NET (C#) Question button without submit

Is there ASP button that won't submit post form data.

Whenever I click an asp button it post form data and I want to change that behavior so I can post some other form data I will create it programmatically.

thanks a lot
Any help will be much appreciated

Answer Source

You need to use JavaScript and intercept the onclick event, and there you make an Ajax call.

In the event handler, return false and your form won't be submitted. Something like this:

    function on_s() {
       /// do some AJAX with JQuery or any other library
       $.ajax({ url: "your_asp_entry.aspx" });
       // you can add some processing to the AJAX call
       return false;
<form runat="server">
<asp:Button id="b1" Text="Submit" runat="server" OnClick="return on_s();" />

On your_asp_entry.aspx you do whatever you need to invoke your C# function/method.

Update: changed the answer after OP said on the comments he/she needs to invoke a C# function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download