Adam Storr
Adam Storr

Reputation: 1450

ASP.net __doPostBack is Refreshing my Javascript

It seems that one of my __doPostBack methods (on a LinkButton) is refreshing the javascript on my page... which is causing some of my <div>s to be hidden... any advice on how I can avoid this?

Code:

<asp:LinkButton runat="server" ID="_lnkRefreshImage" OnClick="_lnkRefreshImage_Click"  CssClass="refreshImage" CausesValidation="false">Refresh</asp:LinkButton>

Upvotes: 0

Views: 1657

Answers (1)

Oded
Oded

Reputation: 499052

Javascript runs in the browser, but the __doPostBack method causes the page to post back to the server - you can't expect the Javascript to retain state when this happens, not without "help".

You have different options:

  • Change the div elements to be server side and set their visibility on the server side
  • Have a hidden input that holds the visibility state of the different divs and in your javascript query it on page load to set the visibility
  • Not use a LinkButton but some client side markup so a postback doesn't occur
  • Use AJAX to communicate with the server

Upvotes: 3

Related Questions