.NET LinkButtons
page 4 of 6
by Troy Karhoff
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24575/ 30

Adding LinkButtons
Now that the web page is designed, the LinkButtons can be added. The LinkButtons are added dynamically using code. The System.Web.UI.WebControls.LinkButton control is instantiated and assigned to _LB1. The Text property is used for rendering the hyperlink label. That is, the text that sits between <a></a>. The CommandName and CommandArgument are what's it all about. Use the CommandArgument property to specify an argument that complements the CommandName property. What might have been placed on the querystring, will now simply be assigned in the CommandName and/or CommandArgument properties. In my example, I'm really just using the CommandArgument property for storing the ProductId of each product link. The CommandName is used to identify my grouping of links which happen to be the same - they're all products.
    void BuildLinkList()
        for (int i=1; i<=10; i++)
            LinkButton _LB1 = new LinkButton();
            _LB1.Text = hashProductName[i].ToString();
            _LB1.CssClass = "ProductLinks";
            _LB1.CommandName = "Products";
            _LB1.CommandArgument = i.ToString() ;

View Entire Article

User Comments

Title: please upload simple example   
Name: Abidha
Date: 2010-03-01 2:00:57 AM
this seems difficult
Title: Help for many developers!!   
Name: Vjeran
Date: 2006-03-29 12:46:51 PM
Well.. i had problem, which is not only mine, and many developers don't know what to do but i found and answer!! Problem is in fact that, if u want to use postback u must generate controls after postback page load. If u don't render do this, evenhadler doesn't work... (?? it doesn't make sense viewstate in table control..).. Now everything works..
Title: Link Button Despair   
Name: Bruce
Date: 2005-04-04 5:15:19 PM
I was looking for a simple example showing a link within a page linking to another section of that page.
This must be so obvious or so complex that no-one seems to be able to write a simple example.
Looking at the source of other pages that perform this miracle is unhelpful. Could you try supplying a meaningful example that sheds some light on this very desirable tool, please?
Title: Stale content   
Name: Diane
Date: 2004-12-30 11:14:03 AM
I've been trying to find some information on using a link button for a week now. I'm finding that all the books and websites use the same limited set of examples. I will learn nothing more from your example here, than I did seeing it somewhere else. Why not go into aspects of the control that everyone else does NOT cover?
Title: broken like   
Name: Tim
Date: 2004-10-05 12:33:35 PM
this page is a broken url on the main menu

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-07-15 5:59:40 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search