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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:24:31+00:00 2026-05-11T12:24:31+00:00

Classic scenario: Take user input, get a search-result and display it in pages to

  • 0

Classic scenario: Take user input, get a search-result and display it in pages to the user. I then need to display buttons for First, Next, Previous etc, and I maintain the users current page in viewstate. All is good, works fine.

Then I need to implement clickable page numbers, ie. 1-2-3-4-5-6 etc.

Rendering them is simple. I generate a linkbutton control at runtime, add commandargument with the page number and add a handler to it, so click are to be handled. Then I add it to a placeholder, and it is displayed as expected.

But then… If I did not already have a shaved head, I would be pulling out my hair getting the events to fire as expected every time.

How should I do this, so my events are always wired up and able to fire when the paging-linkbuttons are called?

Below is the important parts of the code, some pseudo to make it (hopefully) easier to understand, what I am doing.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load   If Not Page.IsPostBack Then      Search()   End If End Sub  Sub Search     'Misc databinding stuff, searches and displays results for the page specified in Me.CurrentPage     RenderPagingControls() End Sub  Sub RenderPagingControls    'loop throug pagenumbers, Build a linkbutton control, add it to a placeholder     AddHandler lbn.Click, AddressOf lbnNumber_Click     lblPageNumbers.Controls.Add(lbn)     ...  End Sub  Protected Sub lbnNumber_Click(ByVal sender As Object, ByVal e As EventArgs)     Dim b As LinkButton = CType(sender, LinkButton)     Me.CurrentPage = CInt(b.CommandArgument)     Search() End Sub  Public Property CurrentPage() As Integer     Get         Dim o As Object = Me.ViewState('CurrentPage')         If o Is Nothing Then             Return 1         Else             Return CType(o, Integer)         End If     End Get     Set(ByVal value As Integer)         Me.ViewState('CurrentPage') = value     End Set End Property  Protected Sub lbnNumber_Click(ByVal sender As Object, ByVal e As EventArgs)     Dim b As LinkButton = CType(sender, LinkButton)     Me.CurrentPage = CInt(b.CommandArgument)     Search() End Sub 
  • 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. 2026-05-11T12:24:32+00:00Added an answer on May 11, 2026 at 12:24 pm

    I’m going to recommend against a LinkButton and recommend Hyperlinks / QueryString parameters instead. For several reasons:

    1. Your page will be much more efficient without the viewstate overhead of a link button.
    2. If these are public facing pages, you’ll get better indexing of all the pages if they can be accessed via hyperlinks (and indexed via search engines).
    3. You’ll find them much easier to implement. No event management, etc.

    You would redefine your CurrentPage method as (hopefully this is correct, I’m better at C# than vb.net):

    Public Property CurrentPage() As Integer     Get         Dim o As Object = Me.Request.QueryString('page')         If o Is Nothing Then             Return 1         Else             Return CType(o, Integer)         End If     End Get End Property 

    Then just add hyperlinks for each page.

    <a href='mypage.aspx?page=1'>1</a> - <a href='mypage.aspx?page=2'>2</a> etc... 

    Alternative: If you want to use the LinkButton, you might want to consider putting a single LinkButton in a repeater. Then the only event you have to worry about is the OnItemCommand event. Then no dynamic controls or events. Something like this:

    <asp:Repeater ID='rptPages' runat='server' OnItemCommand='doPaging'>   <ItemTemplate>     <asp:LinkButton ID='LinkButton1' runat='server' Text='<%# (Container.DataItem).ToString()  %>'     CommandArgument='<%# (Container.DataItem).ToString() %>' />   </ItemTemplate>   <SeparatorTemplate>-</SeparatorTemplate> </asp:Repeater> 

    Bind this control to an array (or list) of consecutive Integers (as many are there are pages). Then in your doPaging function (as I call it), check RepeaterCommandEventArgs.CommandArgument to get the page number.

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

Sidebar

Related Questions

I need ideas... I have a classic scenario with a twist, containing the following
I'm trying to do the classic Insert/Update scenario where I need to update existing
I have an interesting scenario that I need assistance with. I have a classic
I'm running into the classic scenario where, when creating Word COM objects in .NET
Here is the scenario.. ===== scanario 1 ===== 1. Document Library Gatorate Classic 2.
I have the classic scenario with 2 tables and a junction table. Let's say,
I have a classic Order -> Order Row scenario something like this: public class
Here's a classic works on my machine, but not in production scenario. ASP.NET app
Classic scenario, where an order has order lines. The client wants to be able
Here is my scenario... I'm working on a server that is http:// in Classic

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.