1

I'm using the <asp:LinkButton />’s OnClick function on the server side to fetch data. I'm using OnClientClick to open a popup and populate data. But the page refreshes when I click the button. Please see the attached code and help me to fix the issue.

<asp:LinkButton ID="lnkEdit_Bill" runat="server" CssClass="lnkAddressButton" OnClientClick="javascript:ShowDialog_Both_New('Invoice','edit');" OnClick="lnkEdit_Bill_Click_new" >Edit</asp:LinkButton>
3
  • StackOverflow is not a code writing service. You need to write some code and if you get stuck, post the code and explain where you got stuck. Also, pretty sure this has been asked before. Search. Commented May 11, 2020 at 7:36
  • Obviously i posted this after i got stuck, and my statement clears what the issue is, if you've any solution provide me, i've tried different solutions but all in vain :) Commented May 11, 2020 at 8:20
  • So do you want to open dialog first, then call lnkEdit_Bill_Click_new right? Commented May 14, 2020 at 8:35

2 Answers 2

2

Google event.preventDefault(), I believe i've used that previously to prevent a postback. Also remove the OnClick, if that's not what you want, and just use OnClientClick.

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

Comments

1

Bro, if you don't want the postback, just fire the javascript. and you definitely don't need the server control. which you can present your code as below:

<a href="#" onclick="ShowDialog_Both_New('Invoice','edit'); return false;">Edit</a>

Let's says if you still insist want to user ASP.NET server control of LinkButton, then you can do something like this:

<asp:LinkButton ID="lnkEdit_Bill" runat="server" CssClass="lnkAddressButton"
OnClientClick="ShowDialog_Both_New('Invoice','edit'); return false;" >
Edit
</asp:LinkButton>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.