Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:28:10+00:00 2026-05-24T07:28:10+00:00

OK, I am most likely just missing something basic but I am super frustrated

  • 0

OK, I am most likely just missing something basic but I am super frustrated by this.

  public partial class myClass: System.Web.UI.Page
    { 
      public String pageHtml{
        get
        {
            if (ViewState["pageHtml"] != null)
            {
                return (string)ViewState["pageHtml"];
            }
            else
            {
                return null;
            }
        }
        set
        {
            ViewState["pageHtml"] = value;
        }
    }
      protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sbOut = new StringBuilder();
            StringWriter swOut = new StringWriter(sbOut);
            HtmlTextWriter htwOut = new HtmlTextWriter(swOut);
            base.Render(htwOut);
            string sOut = sbOut.ToString();
            pageHtml = sOut;
            writer.Write(sOut);

        }
      protected void btnDownloadPage_Click(object sender, EventArgs e)
        {

            DownloadTextAsFile("test", pageHtml, "aspx");

        }

        public void DownloadTextAsFile(string filename, string content, string extention)
        {


            string downloadFileName = filename + "." + extention;

            Response.AddHeader("Content-disposition", "attachment; filename=" + downloadFileName);
            Response.ContentType = "application/octet-stream";
            Response.Write(content);
            Response.End();
        }

}

when the DownloadPage button is clicked pageHtml is always null. What gives? I have tried moving the “pageHtml = sOut;” To after the “writer.Write(sOut);” And I have tried making pageHtml not persist to the viewstate but no such luck. (also I am aware my pageHtml get is not really checking anything as it returns null if ViewState[“pageHtml”] is null and I could just return ViewState[“pageHtml”] without the if-else check but I don’t care about that right now)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:28:10+00:00Added an answer on May 24, 2026 at 7:28 am

    I think the ViewState doesn’t survive after a postback (your button click).
    Try using session state instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is most likely not an easy one but here is the situation: I
I know this is most-likely a simple question but when you restore a database
I know $_SERVER['DOCUMENT_ROOT'] returns the document root (most likely something like /home/user/public_html), but is
My keystore has gone missing. I most likely deleted it by mistake, but I
I'm most likely going about this the wrong way, but I was wondering if
I guess this is an odd one, and the answer is most likely it
I'm pulling in xml using the cocoa NSXmlParser. Since this process most likely won't
I might be missing something obvious but is there a reference somewhere about what
chances are if you are seeing this you most likely saw my last question
I'm just starting to use Eclipse and I feel like I'm missing something in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.