dynamic buttons, dynamic events

Here is the thing...

i need to generate different links to a page from a database... like

link a === goes to page1.aspx?id=1
link b === goes to page1.aspx?id=2

 but i dont want to pass the id through the url.

i think one way is to create instead hyperlinks, is create dynamic buttons but how do i create differents event to each button?

or is there another better way?

thanxs a lot

10/17/2007 10:09:48 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 20

If I understand correctly, you're trying to create dynamic links based on id's in the database?

I would use a Repeater/Datalist type control.  In the ItemTemplate, you could use a LinkButton (which will cause a PostBack) and in the CommandArgument, pass yourself the Id.

         <asp:datalist id="DataList1" runat="server">
                <asp:linkbutton id="LinkButton1" runat="server" commandargument='<%# Eval("YourIdHere") %>' onclick="LinkButton1_Click">Text Here</asp:linkbutton>

When they click the LinkButton, they all call the same method (LinkButton1_Click) but in that method you can do something like this:

    protected void LinkButton1_Click(object sender, EventArgs e)
        LinkButton myLinkButton = sender as LinkButton;

        int theId = int.Parse(myLinkButton.CommandArgument);

You now have the Id, and you can then do a Server.Transfer, or Response.Redirect based on that Id.




10/17/2007 11:30:28 PM



10/18/2007 6:16:47 PM

Why do you need more then one parameter in the command argument?  Your original question asked about creating links based on the ID coming from your database....

 Maybe we need a better explanation of what you're trying to do (with some sample data?) and then I can help you further.



10/18/2007 7:54:15 PM

hey man... your previous answer resolve my problem....

but doing some modifications to the application i need to pass another parameter...

so i was asking if theres any way i can pass more than one parameter...

10/18/2007 8:21:30 PM

Passing multiple parameters...off the top of my head, I would probably create a CSV list of parameters...(assuming of course that you're not talking a ton
of parameters here...)  Then on the click event, you'll be able to split the commandargument string by the comma....

  <asp:linkbutton id="testLinkButton" runat="server" commandargument='<%# Eval("Parameter1") + "," + Eval("Parameter2") %>'>Text Here</asp:linkbutton>

 Hope that answers your additional question.

10/18/2007 8:38:43 PM

if im passing from one page to another how do i retreive the value from the commandargumeny?


10/18/2007 8:44:06 PM

Well...you could have a Public Property in the code-behind...which you could set with the CommandArgument on the LinkButton_Click event...at which point you could do a Server.Transfer (make sure you set the second parameter to "True" to persist the page state when you go to the new page)....on the new page, you can use the Context.Handler in the Page_Load to get the original page, and check the value of the Public Property that you created.  

This link talks about the Server.Transfer, and has a simple example on using the Context.Handler to load the calling page:


 Hope this helps.


10/18/2007 9:46:44 PM

Similar Artilces:

Dynamically adding buttons to web form and wiring up the onclick event.
I have a web form that is generated at runtime with a number of dynamically created buttons. Creating the buttons is easy, but wiring them up is not. I would love to use the cold behind and a single onclick event. Then based on the id, I can call a single method that does an operation. Each button will perform the same tasks. The user can chose one of three tasks. I though I would either have a dropdown or three radio buttons for this. Alternatively, I could have some javascript, but I am not quiet sure how to post back with javascript and if all the buttons will make it more difficult. Does...

Creating a Dynamic button from another Dynamic Button
Hi, I have created a button Dynamically as follows: Button b=new Button(); b.Text="Hello"; this.Controls.Add(b); b.Show(); How to create another Button(some Button) when clicked on the above created button. You have to handle the on click event of the dynamic button. In the onclick event you can create another button in the same way as you have done. Remember to create the dynamic button on every post back other wise you will not be able to capture the click event..Vikram www.vikramlakhotia.comPlease mark the answer if it helped you try this link: http://support.mic...

Dynamic Generation of Web Forms in C#.net
I am new to c# and vs.net studio as such and am seekin help for my project. It deals with generating webforms at runtime by takin in inputs from the user. The user will input no. of webfroms to be generated and all the attributes he want in them. I have got the datamodel right for this where all the info by the user is stored in sql server database. During runtime my application should read it from that database and based upon that generated these .aspx forms which can be posted online for use. I think it would help if you explained what the application would accomplish. It sounds like yo...

Dynamically generated Button inside dynamically generated GridView inside ListView not firing Event
I've done tons of searching on this one to no real avail, so I'm posting here.  As a note, I've found multiple pages discussing this problem, but all of those solutions utilized a placeholder control, which I don't have the luxury of using.Here's a basic overview of what I have:A ListView ControlEmbedded into the ListViewItem is a GridView, utilizing a dynamically generated DataTable (due to a variable number of columns)A LinkButton in the footer of each GridView cell, which should fire an event to populate and show a Modal Dialog.The problem is that I can never get ...

PostBack Events
Hello... Ok, Let me explain first. BasePage.CS Defautlt Page - > Inherits basePage baseapge has a method AddCustomButton(ImageButton btn){.....} which adds the button to a collection, and on prerender, adds all the buttons to the page. Default craetes the button, and attaches an event to the button. Passes it to AddCustomButtonMethod, and moves along. The button is only added on First Page Load. BasePage stores the button definitiosn in viewstate, then on loadstate, recreates the buttons. This works, but the events are missing, and I dont know how to make basepage reattach events,...

.NET 1.1 Web Form
I am scratching my head trying to figure out why my events button (Lighting Bolt) is not displaying when I select buttons in Visual Studio 2003.  Has anybody had this happen before? I am tired into Visual Source Safe and wonder if that has anything to do with it?Moojjoo Õ¿Õ http://www.mmwebs.comhttp://moojjoo.blogspot.com/ Ummm>>>   That is the difference between C# and VB.NET.  VB.NET does not display the Lightning Bolt under properties in VS 2003.Moojjoo Õ¿Õ http://www.mmwebs.comhttp://moojjoo.blogspot.com/...

Please guide
Hi, I am creating dynamic panels and each of these panels have an image and a button. I would like to show a modal popup when the button of the panel is clicked. Contents of popup depend on which button was clicked. I would sincerely appreciate if some one could guide me if this is possible with Ajax and AjaxControltoolkit. Till now I tried to create modalpopupextended dynamically in the click event of button and page fails with an error message that TargetControl could not be found. Please guide. Regards & thanks Kapil    Hi Kapil, Unfortunately, the ModalPopup must h...

Dynamic tables, dynamic object and events
Hi,I have a problem. I have a page where I generate tablerows and tableelemnts dynamically at runtime depending on the data from the datasource. To some of the table elements I need to add objects live liveimages. Now I would need to handle events from these objects. As they are generated at runtime, I cannot write an eventhandler for each of these objects. Is there a way to solve this?TIAWombel__________________________________________Thomas Wrobelwaslos.de It's possible to have event handlers for dynamic controls. Button newButton = new Button();newButton.ID = "newButton_01";controlPlac...

Dynamically assigned events to Dynamic controls
Ok I have seen this happen to many people. I have read the suggestions and feel I am still missing something. The created imagebuttons do not fire the assigned btnImg_Click method although the page does post back. Here is my code for reference. public class Navigation : System.Web.UI.UserControl { private Security _security; private PrivilegeDS _privileges; private void Page_Load(object sender, System.EventArgs e) { _security = (Security)HttpContext.Current.Session["SECURITY"]; _privileges = _security.GetUserPriviledges(); crea...

wiring up dynamic button in dynamic control
I have created a web control that derives from the panel class.  It has a table to which I add rows via a public method.  Finally, I add a footer row with 2 navigation buttons (next, previous).  Then in my containing page, I have an array of these panels created.  I'm trying to figure out how to wire up the buttons that are added so they hide/show the right panels.  I've got this... public void AddFooter(Direction which) { TableRow r = new TableRow(); TableCell c = new TableCell(); Button bNext; Button bPrevious; switch (which) { case Direction.Next: bNext ...

Dynamically loaded Web User Control .ascx button click event handler not called on second time click
I have an ascx control (that performs actions for an entity) being added dynamically to accordion panes, and then the panes are added to an ajax accordion control, so that the accordion can contain multiple panes with each pane containing one ascx control. The ascx control contains a delete button which removes the entity from the database. Once the entity is removed, I need to reflect this deletion in the parent page by removing the accordion pane from the accordion. To do this I created a delegate function and which is called from the parent page to rebind the accordion and hence not d...

Dynamically created button & event handler for the button
I know that this question has been addressed a few times on these forums. I have looked over the posts that are refering to this process but I am still very confused. So I am posting here to see if someone could clear it up for me, I am a beginner at this so I must not be understanding previous posts. Here is the run down of what I am trying to accomplish. I have a page that has one button on it (button1) and a panel (panel1). When I click button1 I would like it to display another button (button2) on panel1. Then when you click button2 it will display a label on the panel. Panel1 a...

Dynamic Button Events
I haven't been having any luck adding event handlers to dynamic buttons. It seems as if the event never gets raised. An example of the code is below. Button newButton; for(some loop condition) {    newButton = new Button();    newButton.ID = some unique id;    newButton.Click += new System.EventHandler(this.some event);    // then add the button to a new cell, then to an existing row, then to an existing table } The event I'm specifying never gets called. This code is being called in the PageLoad event. Any help would be gre...

Dynamic Buttons and Forms ?
I have some buy now buttons on my website and those are created dynamically and I want that when user clicks on that button this form thing is filled with button related information. <form target="paypal"   action="https://www.paypal.com/cgi-bin/webscr"   method="post">   <input type="image" src="https://www.sandbox.paypal.com/      en_US/i/btn/x-click-but22.gif"       border="0" name="submit" alt="Make payments with PayPal - &n...

Web resources about - dynamic buttons, dynamic events - asp.net.web-forms

Dynamics - Wikipedia, the free encyclopedia
Brownian dynamics , the occurrence of Langevin dynamics in the motion of particles in solution (e.g. a grain in water, as was first seen by Brown); ...

Datacenter Dynamics
Datacenterdynamics for data center information, conferences, news, videos, whitepapers and reports globally

Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find ...
Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find a Chiropractor

Master & Dynamic MW60 wireless headphones offer style and performance
Priced at £419 (€579/$549), there's no denying that Master & Dynamic's wireless MW60 headphones are expensive—but boy do they look it. Cast out ...

Playing ‘GTA V’ in a Force Dynamics motion simulator looks like a ton of fun
It's been a few weeks since I last sat down and played Grand Theft Auto V . Although it's still one of my favorite games of both this generation ...

General Dynamics Corporation Delivers The Future of American Shipping
American Petroleum Tankers receives delivery of first ECO class tanker from General Dynamics\' NASSCO.

Microsoft Dynamics AX delivers the power of the cloud to businesses
Microsoft has announced that the next release of its flagship ERP solution, Microsoft Dynamics AX, will be generally available in the first quarter ...

Microsoft Releases Dynamics CRM 2016 With New Analytics Features
DAILY VIDEO: Microsoft launches Dynamics CRM 2016; Encryption ban wouldn't have affected Paris attackers' plans; VTech hacker obtains kids' photos, ...

Lower Prices, Increased Investment: The Green Dynamic Duo
The price of solar generated electricity is falling. It may be about to fall even further. Bloomberg reports that the main ingredient in a solar ...

The Social Dynamics of Penguin Huddles Are More Complex Than We Thought
... penguins huddle together for warmth during those punishing Antarctic storms, taking turns being at the center of the huddle. The social dynamics ...

Resources last updated: 12/9/2015 6:15:17 AM