I have created a simple SharePoint web part with HTMLAnchor tag with server click event handler by following the below article.


Code Piece: AnchorButton.ServerClick += new System.EventHandler(this.HtmlAnchor_Click);

In the development environment (SharePoint 2013) it works fine, but when I deploy the same solution in production, when I click on this button, it is refreshing my whole page so the expected results are missing.

Is this environment related issue? How do I troubleshoot this behavior/issue.

Thank You


It really depends on what your "expected results" are, but a server control click will issue a full postback. If your data resides in ViewState (other server controls) then checking for IsPostBack on the Page_Load might be what you need.

| improve this answer | |
  • Thanks for your response. On page load I am constructing some text and storing in a hidden text column on the page. When this button is clicked, I am exporting that content to Excel file using this code, HttpContext.Current.Response.Write("stringvalue");. Instead of prompting to save the file, it is just refreshing the page. – Crow Canyon Nov 30 '18 at 12:14
  • Are you checking for IsPostBack? A full reload is going to erase that hidden field from ViewState. – Derek Gusoff Nov 30 '18 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.