RE: How to detect when a dynamically added control is clicked

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William Main (wmain_at_newsgroups.nospam)
Date: 07/12/04


Date: Sun, 11 Jul 2004 17:52:05 -0700

Also have a look at the AddHandler method

-- 
William Main
"William Main" wrote:
> take a look at Microsoft Knowledge Base Article - 317515 
> HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET
> 
> -- 
> William Main
> 
> 
> "who be dat?" wrote:
> 
> > I need some help here.  I'm creating a list on a page where the list is
> > created from a dataset with two tables linked with a datarelation.  The
> > first table is a list of groups while the second table is a list of items in
> > that group.  I want to show these items in what would basically look a lot
> > like a tree view.  I decided to just show everything in a placeholder
> > control on an aspx form.  First, I display a groupname from the first table
> > by creating a literalcontrol.  Then, under the groupname I display all the
> > items that go along with that group in a list.  For each group, I repeat
> > this (see code below).  All this is done in a page load event.  Thing is,
> > each item in a group's list is a linkbutton.  I need to be able to detect
> > when a given linkbutton is clicked, put an item assigned in the linkbutton's
> > commandargument property in a session object, then redirect the browser to
> > another page.  Thing is, I am unable to execute code when one of these
> > linkbuttons are clicked.  Any ideas on how I can do this?  If this isn't the
> > best way to do this, please let me know how.  Some example code or a link to
> > a website with a sample and code would be great.  I tried to think of a way
> > to do this by having a datagrid with a datalist control in each cell where
> > the groupname would be listed in the cell and the items would show up in the
> > datalist as linkbuttons.  I couldn't quite get it to work.  Below is the
> > code I'm currently using to attempt this.  The controls are inserted into a
> > placeholder control in the form.  I didn't include the aspx code as it's
> > fairly straight forward.  If it's needed, just let me know.  Thanks!!
> > 
> > Chris Smith
> > 
> > begin code -----
> > 
> > ....code snipped which pulls data from SQL Server tables and stores them in
> > datatables....
> > dsForum.Relations.Add("groupid_relation", _
> > 
> > 
> > dsForum.Tables("Grouplist").Columns(0), _
> > 
> > 
> > dsForum.Tables("ForumList").Columns(0))
> > 
> > For Each rowGroup In dsForum.Tables("groupList").Rows
> > 
> >     plhPlaceHolder.Controls.Add(New LiteralControl("<P>"))
> > 
> >     plhPlaceHolder.Controls.Add(New LiteralControl(CStr(rowGroup(1))))
> > 
> >     For Each rowForum In rowGroup.GetChildRows("Groupid_relation")
> > 
> >         Dim link As New LinkButton
> > 
> >         link.Text = Trim(CStr(rowForum(2)))
> > 
> >         link.CommandArgument = CStr(rowForum(1))
> > 
> >         plhPlaceHolder.Controls.Add(New LiteralControl("<BR><LI>"))
> > 
> >         plhPlaceHolder.Controls.Add(link)
> > 
> >     Next
> > 
> >     plhPlaceHolder.Controls.Add(New LiteralControl("</P>"))
> > 
> > Next
> > 
> > 
> > 


Relevant Pages

  • RE: How to detect when a dynamically added control is clicked
    ... > control on an aspx form. ... I display a groupname from the first table ... > each item in a group's list is a linkbutton. ... > the groupname would be listed in the cell and the items would show up in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • How to detect when a dynamically added control is clicked
    ... control on an aspx form. ... I display a groupname from the first table ... each item in a group's list is a linkbutton. ... the groupname would be listed in the cell and the items would show up in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: How to detect when a dynamically added control is clicked
    ... Private Sub Page_LoadHandles MyBase.Load ... > control on an aspx form. ... I display a groupname from the first table ... > each item in a group's list is a linkbutton. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: How to detect when a dynamically added control is clicked
    ... > control on an aspx form. ... I display a groupname from the first table ... > each item in a group's list is a linkbutton. ... > the groupname would be listed in the cell and the items would show up in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Naming container
    ... The linkbutton's parent is a class called Target. ... control we have made ourselves - and hence it is properly not correct. ... foreach (HintSetting s in Settings) { ... you're using a LinkButton control nested in another ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)