If possible, read up on the ASP.NET page lifecycle. You will learn
that when a page posts back, the control tree is recreated,
eventhandlers are reattached, the Page_Load event is called and then
only the event that raised the control is raised.

In your case, since the control that raises the event (linkbutton) is
dynamic control, it's associated event is never raised. The only way
to counter this is recreate the entire table (gridview?) along with
the linkbuttons that loaded the first time in the Page_Load method (on
postback). Then the eventhandler for the associated linkbutton will
fire.

On Feb 11, 1:58 pm, Helvin <[email protected]> wrote:
> Hi,
>
> My asp.net page lets users enter a searchstring, and then shows a
> search results table, which is dynamically created after the user
> clicks the submit button. The search results table includes some
> linkbuttons. These linkbuttons post to another page, by its
> postBackUrl property. This is working fine, however, its also supposed
> to call another sub. This is not working, and after much research, I
> now guess that the problem is because when the page posts back after
> the linkbutton's click, the linkbutton, which is created dynamically
> does not exist anymore. So the page that it posts to loads instead.
>
> Does anyone have any ideas as to how I can alter my code so that when
> the linkbutton is clicked, my sub runs?
> I cannot create the linkbuttons in page_init, as the no. of rows in
> the search results table depends on the searchstring entered by the
> user.
>
> Has anyone encountered this problem before? My code is quite long, but
> if you would like to see, I can include it.
>
> Thanks in advance,
> Helvin

Reply via email to