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 6812889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:30:16+00:00 2026-05-26T20:30:16+00:00

Please See The Simple Example Below For Understanding My situation. (Attention To Comments Inside

  • 0

Please See The Simple Example Below For Understanding My situation.
(Attention To Comments Inside Codes)

Master Page (ASPX) :

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="NiceFileExplorer.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span runat="server" id="SummaryContainer">
            <asp:Label ID="lblDownload_Count_By_UserID_Today_Title" runat="server" Text="Count :"
                ToolTip="Your Download Count-Today" CssClass="lblTitleInStatistics_Master"></asp:Label>
            <asp:Label ID="lblDownload_Count_By_UserID_Today" runat="server" Text="<%# Download_Count_By_UserID_Today() %>"
                CssClass="lblCountInStatistics_Master" ToolTip="Your Download Count-Today"></asp:Label>
            <span style="color: white;">&nbsp;|&nbsp;</span>
            <asp:Label ID="lblDownload_Size_By_UserID_Today_Title" runat="server" Text="Size :"
                ToolTip="Your Download Size-Today" CssClass="lblTitleInStatistics_Master"></asp:Label>
            <asp:Label ID="lblDownload_Size_By_UserID_Today" runat="server" Text="<%# Download_Size_By_UserID_Today() %>"
                CssClass="lblCountInStatistics_Master" ToolTip="Your Download Size-Today"></asp:Label>
        </span>
    </div>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" ViewStateMode="Inherit" ClientIDMode="Static">
    </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

as you see i set ClientIDMode=”Static”.

Master Page (CodeBehind) :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NiceFileExplorer
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             SummaryContainer.DataBind();
        }

        protected string Download_Count_By_UserID_Today()
        {
            //Read New Count From DataBase
            //return Count;
            return "Test";
        }

        protected string Download_Size_By_UserID_Today()
        {
            //Read New Size From DataBase
            //return Size;
            return "Test";
        }
    }
}

Content Page (ASPX) :

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NiceFileExplorer.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Conntent Page
</asp:Content>

Content Page (CodeBehind) :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NiceFileExplorer
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyMethod();
        }

        private void MyMethod()
        {
            //Add New Downloaded File Info To DataBase(); -> For Getting Count And Size Of Them Per Day

            //Here I Wand To Access Master Page Controls And Update Count And Size Lables
            //So, I Tried Codes Below Without Any Results -> How Can I Fix This ?
            var SummaryContainer = (System.Web.UI.HtmlControls.HtmlGenericControl)Page.Master.FindControl("SummaryContainer");
            SummaryContainer.DataBind();
            SummaryContainer.InnerHtml = "<h2>Hello World</h2>";

            //After Update Those Lables Failed, I test the codes Below With Null Execption Error -> How Can I Fix This ?
            var lblDownload_Count_By_UserID_Today_Title = (Label)Page.Master.FindControl("lblDownload_Count_By_UserID_Today_Title");
            lblDownload_Count_By_UserID_Today_Title.Text = "test";

            DwonloadFile();
        }

        private void DwonloadFile()
        {
            //A Class (Method) That Shows Download Window To My Users, So Page_Load Of Master Will Never Fire...
            //And This Is The Reason That I want to update count & size lables from content page
        }

    }
}

i want to DataBind SummaryContainer(a span) from content page’s code-behind.
so i tried the codes below :

            var SummaryContainer = (System.Web.UI.HtmlControls.HtmlGenericControl)Page.Master.FindControl("SummaryContainer");
            SummaryContainer.DataBind():

but i can not see new results.
After That Fail I tried to find a label’s text(that label is inside Master) from content page code behind for test like below : var

lblDownload_Count_By_UserID_Today_Title = (Label)Page.Master.FindControl("lblDownload_Count_By_UserID_Today_Title");
                    lblDownload_Count_By_UserID_Today_Title.Text = "test"; 

but i have System.NullReferenceException ERROR :

Object reference not set to an instance of an object.

how can i fix that error and force that span to show me new results?

thanks in advance

  • 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-26T20:30:17+00:00Added an answer on May 26, 2026 at 8:30 pm

    In a project I used an interface on the masterpage:

    ((IMasterPage)Page.Master).MyProperty = "test";
    

    But in your case, personally instead of putting all that on the master page, I’d put your SummaryContainer into a UserControl, and have another ContentPlaceHolder.
    Then the Page_Load method will be able to access the properties, and on future pages you could have different summary info by filling that first PlaceHolder with a different UserControl.

    Also debugging stupid errors, is the Null exception being thrown at .Master.FindControl or at lbl.Text?

    I’m unable to debug it for myself right now, but would it be due to the page life cycle, namely that Content Page Load comes before Master Page Load?

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

Sidebar

Related Questions

everyone. Please see example below. I'd like to supply a string to 'schedule_action' method
Please see this simple CATiledLayer example https://github.com/seanhess/CATiledLayer-Example It consists of one viewController with a
Please see code below. The destructors are never called. Anyone know why and how
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
I have an Adorner which adornes a Border (please see screenshot below). The MouseDown
I have sql server procedure, please see below. ALTER PROCEDURE [dbo].[uspInsertDelegate] ( @CourseID int,
first, please see the blog as the link showed below: http://blogs.nitobi.com/joe/2008/10/17/phonegap-now-for-android/comment-page-1/#comment-12918 the author made
Please see my answer to this question below. It is based upon Kevin's input,
I'm trying out very simple search popup on the JqGrid. Please see the code
Please see the sample code below. Initially the grid comes up with no sort

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.