473,748 Members | 5,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1053
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(LinkBut ton button in buttons)
button.Click += new EventHandler(Li nkButton_Click) ;

// Handling the event
private void LinkButton_Clic k(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******** *************** ***********@mic rosoft.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
1262
by: Umut Tezduyar | last post by:
public class WebForm1 : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { }
0
973
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 implemented an event onClick which task is to create LinkButton subcategories. When the page is loaded main categories are displayed, when I click on any of that buttons a subcategories will appear on the screen.
10
3877
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 forums, and noone wants to touch it. I tried to attach a literal control to a placeholder: <>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>
4
1337
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 can create the label and the webcontrol dinamically with no errors, but only the Label appear in the panel when the page is shown in the client browser.
2
4306
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 , Load , PreRender , Render ) ... ? I need to create various .ascx controls on-the-fly , calling Init() methods with different signatures ... I think the syntax might be :
7
2531
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 several methods that are working fine. The problem is if I want to dynamically assign an event handler to the object, the event handler is not called. What am I doing wrong? Below is a sample HTML doc with everything in place. <!DOCTYPE HTML PUBLIC...
2
3926
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 well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever possible to make the app more efficient and less resource demanding. On one page there are 2...
2
1837
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 the button's Click event to a procedure but it never fires... When the client is viewing the page that has the control in it, and click the button, the page does the postback, the control passes to the usercontrol
3
1795
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 page that has been rendered and unloaded generates these exceptions - A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll A first chance exception of type 'System.Threading.ThreadAbortException' occurred...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.