473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dinamically assigning handler methods to controls on the page

Vi
Hi,
I'm building a screen where I want to allow users to be able to see data one
page at a time.
The users would view the data by clicking on the Page Nr.
The problem is that the number of pages is dynamic, based on how much data
the database returns, and I'm having troubles building the list of page
numbers.
I'm trying to build it using LinkButton controls, but because their number
is dynamic, I don't know how to link their handlers to them.
Or if I declare only one LinkButton and therefore only one handler for it,
how do I know which link was clicked?
What is the proper way to do it?

Thank you.
Nov 18 '05 #1
2 1040
If you hook each LinkButton into the same Click event, the first parameter of
the EventHandler is the sender object. The sender object can be casted to
the LinkButton and you'll know exactly which LinkButton fired the event.

// Hooking into the click event
LinkButton[] buttons;
....
foreach(LinkButton button in buttons)
button.Click += new EventHandler(LinkButton_Click);

// Handling the event
private void LinkButton_Click(object sender, EventArgs e)
{
LinkButton button = sender as LinkButton;
if(button!=null)
{
Response.Output.WriteLine("{0} was clicked!", button.Text);
}
}

Hope that helps.

--
Jason Whitted

"Vi" wrote:
Hi,
I'm building a screen where I want to allow users to be able to see data one
page at a time.
The users would view the data by clicking on the Page Nr.
The problem is that the number of pages is dynamic, based on how much data
the database returns, and I'm having troubles building the list of page
numbers.
I'm trying to build it using LinkButton controls, but because their number
is dynamic, I don't know how to link their handlers to them.
Or if I declare only one LinkButton and therefore only one handler for it,
how do I know which link was clicked?
What is the proper way to do it?

Thank you.

Nov 18 '05 #2
Vi,
I use a pager control for this type of stuff which I wrote. I've been using
it for a couple years, anyways, your aren' the first to ask a similar
question, so I've put it up with a little sample program. VB.Net version
coming over the weekend...hope it helps..

http://openmymind.net/pager/index.html

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Vi" <Vi@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
Hi,
I'm building a screen where I want to allow users to be able to see data one page at a time.
The users would view the data by clicking on the Page Nr.
The problem is that the number of pages is dynamic, based on how much data
the database returns, and I'm having troubles building the list of page
numbers.
I'm trying to build it using LinkButton controls, but because their number
is dynamic, I don't know how to link their handlers to them.
Or if I declare only one LinkButton and therefore only one handler for it,
how do I know which link was clicked?
What is the proper way to do it?

Thank you.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Umut Tezduyar | last post by:
public class WebForm1 : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { }
0
by: Rafi | last post by:
Hi, In my database I have table category where I store diffrent categories and subcategories. I decied to create LinkButtons dinamically with assigned name of category and its id. I also...
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
4
by: Cesar Ronchese | last post by:
Hello. I have a WebForm that contains a Panel object. This panel, at design time is empty. When running, I need to create dinamically a Label and a WebControl (built from the same project). I...
2
by: John A Grandy | last post by:
For ASP.NET UserControls , is it possible to provide multiple overrides of the intrinsic handler methods (those for which the delegate that wires the event to the handler is built-in , such as Init...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
2
by: =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?= | last post by:
hello Inside a usercontrol i create a webcontrol button. I then render it onto a string on the usercontrol to built my UI I need to get access to that control Click event. To do so i try to bind...
3
by: PJ6 | last post by:
Taken out of context I know this may seem like a strange thing to do, but just take this as an academic question if necessary... Calling methods on a persisted control that has been added to a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.