3

Can I avoid postback on button click (don't go in page_load method),

despite, Call the handler directly.

I tried html button, asp button, link button, but didn't get my goal.

Is it possible?

3
  • Call event handler without postback, Is it possible? Yes, it is all you need to do is wrap your button and other content inside Update Panel. Commented Aug 3, 2017 at 9:16
  • Possible duplicate of How to disable postback on an asp Button Commented Aug 3, 2017 at 9:33
  • @Prabhat I tried the same solution, but didn't succeed. Commented Aug 3, 2017 at 18:10

2 Answers 2

4

You can use OnClientClick. It will call the function (jquery function) you want to execute then use return false to avoid pageload. In your button add:

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="yourfunction(); return false;" /> 

If you want to call code behind function without postback then there are two ways to do this:

  1. Use UpdatePanel. You can read this tutorial.

  2. or Use page methods:

Add a static method to your page, decorated with the WebMethod attribute:

[WebMethod] public static void MyMethod(string Param) { } 

Enable page methods in your ScriptManager:

<asp:ScriptManager EnablePageMethods="True" ... /> 

And then you can call it from the client side, using JavaScript (OnClientClick event of your button).

PageMethods.MyMethod("value", successCallback, errorCallback); 

For more details read: http://msdn.microsoft.com/en-us/library/bb398998.aspx

Hope it will help you..!

Sign up to request clarification or add additional context in comments.

Comments

0

Use javascript if you want to disable post back try the below code

<asp:button runat="server".... OnClientClick="myfunction(); return false;" /> 

by doing this,it will cancel the postback

1 Comment

No, I wanna call server side handler, without postback on server. your solution does not carry the program flow to server side.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.