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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:44:37+00:00 2026-06-02T13:44:37+00:00

I have a DataPager, and once it is populated with pages, it throws a

  • 0

I have a DataPager, and once it is populated with pages, it throws a nullreferenceexception. It was kinda weird because back when I have little or no data, it doesn’t throw anything. My code is here:

  private void dataPager_PageIndexChanged(object sender, System.EventArgs e)
    {
        if ((sender as DataPager).Visibility == System.Windows.Visibility.Visible)
        {
            if ((sender as DataPager).PageIndex == (sender as DataPager).PageCount - 1)
            {
                (sender as DataPager).GetVisualDescendants().OfType<Button>().Where(b => b.Name == "NextPageButton").SingleOrDefault().IsEnabled = false;
            }
            else
                (sender as DataPager).GetVisualDescendants().OfType<Button>().Where(b => b.Name == "NextPageButton").SingleOrDefault().IsEnabled = true;
        }
    }

What I don’t get is why does result view of (sender as DataPager).GetVisualDescendants() yield no result when dataPager gets to 4 pages? As you can see, I have already checked if it was Visible for getting visual descendants, and this code is on pageindexchanged event, so it fires as soon as the datapager is loaded. Any thoughts on this one? Any help would be much appreciated. Thanks!

  • 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-06-02T13:44:45+00:00Added an answer on June 2, 2026 at 1:44 pm

    The answer was it fires the pageindexchanged twice. Dunno why, but Silverlight seems to fire pageindexchanged when datapager is loading AND loaded. So it fires this code twice, all I did was added a line that checks if the GetVisualDescendants().Count != 0 and everything went well, atleast, I hope.

    private void dataPager_PageIndexChanged(object sender, System.EventArgs e)
    {
    
        if ((sender as DataPager).Visibility == System.Windows.Visibility.Visible)
        {
          if((sender as DataPager).GetVisualDescendants().Count != 0)
           {
               if ((sender as DataPager).PageIndex == (sender as DataPager).PageCount - 1)
               {
                (sender as DataPager).GetVisualDescendants().OfType<Button>().Where(b => b.Name == "NextPageButton").SingleOrDefault().IsEnabled = false;
               }
               else
                (sender as DataPager).GetVisualDescendants().OfType<Button>().Where(b => b.Name == "NextPageButton").SingleOrDefault().IsEnabled = true;
           }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight application that has a DataGrid and a DataPager. The data
If I have the folling data pager <asp:DataPager ID=DataPager1 runat=server PagedControlID=lstBlogPosts PageSize=1 onprerender=DataPager1_PreRender >
I have a datapager with a pagertemplate. In the template I have a Show
have written this little class, which generates a UUID every time an object of
I have the $user array that contains data with special characters. It seems like
DataPager has some strange behavior. So to situate the problem, I have a DataPagerReapeater
I have a simple ListView paged by a DataPager giving a list of products.
I have a strange problem that I don't understand about DataPager. After changing the
I'm using a DataPager control in my silverlight application. I have different pagers for
I'm experimenting with the Silverlight 4 SDK DataPager. I have some code in my

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.