Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Creating WebControls(System.Web.UI) dynamically in webpart

  Asked By: Damaris    Date: Mar 23    Category: Sharepoint    Views: 2028

I am in need of creating web controls dynamically in a web part on a an event
(button click). I am working on search functionality, based on the search count
I have to render the hyper link( controls.

When I create and use the control from RenderChildControls override method it
is working fine (but these are per created and limited).

any standard way around to get a solution.



1 Answer Found

Answer #1    Answered By: Brianna Olson     Answered On: Mar 23

Since all controls  in a webpart  are declared dynamically  this is
actually fairly easy to do. In the event handler for the button click
use the search  count as the control  for a for loop. Inside the loop
instantiate a Hyperlink control, set the properties, and add it to the
Controls collection of the webpart. If you need to process the click  of
the hyperlink be sure to wireup an event handler in the loop as well.
Then make sure you put code in that event handler to figure out which
hyperlink was clicked.

Didn't find what you were looking for? Find more on Creating WebControls(System.Web.UI) dynamically in webpart Or get search suggestion and latest updates.