Hiding some web page contents from being viewed in page source

Donald Symmons 2,856 Reputation points
2023-05-16T04:50:52.3833333+00:00

Hello,

I sometimes try to see some sites' source code, and most of them have very little to view for a front-page that has too much contents. I always wonder how they did it - hiding some of the page contents? In most cases, I only view styles scripts, and very minimal HTML.

Is there a way I can hide some source code when someone tries to see them in "View page source" ?

Maybe do like I usually see on most sites?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,525 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. QiYou-MSFT 4,311 Reputation points Microsoft Vendor
    2023-05-16T10:21:59.43+00:00

    Hi @Donald Symmons

    The controls and styles of a web page cannot be hidden.

    HTML1

    In fact, those that are hidden are more of the back-end methods written by some framework. They are triggered by things like HTTP requests and APIs.

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="test" OnClick="Button1_Click" />
    </asp:Content>
    
     public partial class About : Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                TextBox1.Text = "Test";
            }
        }
    

    You can see this back-end Button1_Click method, which you can't see here. When we trigger it, he modifies the content of the html page.T1

    T2

    When we trigger this button, the input has an additional value.HTML2

    Best Regards

    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,036 Reputation points
    2023-05-16T15:21:32.9433333+00:00

    Most likely they are dynamically building the html with JavaScript. The view source only shows the download. If you use the browser dev tools to see the current html, you can see everything.