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

  • Home
  • SEARCH
  • 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 6651031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:57:45+00:00 2026-05-26T00:57:45+00:00

I have a button on a page that creates a PDF of the page.

  • 0

I have a button on a page that creates a PDF of the page. I would like to hide the button for the pdf then show it after the pdf is created. I tried the following in codebehind and it does not hide the button.

Private Sub PdfPageButton_ServerClick(sender As Object, e As System.EventArgs) Handles PdfPageButton.ServerClick
    PdfPageButton.Visible = False
    ConvertURLToPDF()
    PdfPageButton.Visible = True
End Sub

Private Sub ConvertURLToPDF()
    Dim urlToConvert As String = HttpContext.Current.Request.Url.AbsoluteUri

    'more code here not displayed...   

    ' Performs the conversion and get the pdf document bytes that you can further 
    ' save to a file or send as a browser response
    Dim pdfBytes As Byte() = pdfConverter.GetPdfBytesFromUrl(urlToConvert)

    ' send the PDF document as a response to the browser for download
    Dim Response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
    Response.Clear()
    Response.AddHeader("Content-Type", "binary/octet-stream")
    Response.AddHeader("Content-Disposition", "attachment; filename=ConversionResult.pdf; size=" & pdfBytes.Length.ToString())
    Response.Flush()
    Response.BinaryWrite(pdfBytes)
    Response.Flush()
    Response.End()
End Sub

However I use [@media print] in css to not display my print button. to bad it doesn’t work in other ways

  • 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-26T00:57:45+00:00Added an answer on May 26, 2026 at 12:57 am

    The reason it doesn’t hide the button is because the page doesn’t get rendered again before this line:

    PdfPageButton.Visible = True
    

    If it were WinForms, your approach would work but on the web you need to do it a bit differently.

    You could hide the button by simply setting a CSS style of display:none in the button’s onclick() event:

    <input type="button" id="pdfBtn" onclick="this.style.display = 'none';" />
    

    but to show it again when the PDF has been generated, you’d either need to refresh the page in its entirety (i.e. a postback), or you could wire up an event listener if you wanted to use AJAX.

    EDIT: Given the extra info that the PDF is of the page itself, could you perhaps add a querystring parameter to the URL, e.g.

    mysite/mypage.aspx?isPDF=1

    Then, in your PageLoad(), add:

    if(Request.QueryString["isPDF"] == "1")
    {
        PdfButton.Visible == false;
    } 
    

    so that the button doesn’t exist when isPDF is set to ‘1’ (or whatever you choose).

    Then, pass that URL with the extra param to the ConvertURLToPDF() method?

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

Sidebar

Related Questions

I would like to have an Add another field button that creates a text
I have a form in an HTM page that, after pressing the submit button,
I have buttons on a page that look like: <p> <a href=view.php> <input type=button
I have an aspx page that on a button click creates a BackgroundWorker and
I have an aspx page that, on a button click, creates an instance of
I have a button on an aspx page that is supposed to send an
I have an aspx page that contains a checkbox, and a button. The button
I have a page with some user selectable options and a button that, when
I have an asp.net page. There is a button Edit on the bottom that
My problem is this I have a base page that creates content dynamically. There

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.