user control problem

R

Rotsey

Hi

I have a ASP.NET 2.0 problem I hope you could help me with, I have had
problems trying to find an answer to this

I will be brief.

I have a user control that has only a <asp:table> tag on it.

I then want to build the control programmatically on page load.

One the controls I add to the table is a LinkButton.

The problem is that the click event I wired up does not fire.

The LinkButton is declared at the user control level like this...

....
....
Public lnk as LinkButton

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

If Not Me.IsPostBack Then

BuildTree(15)

End If

End Sub

Public Sub BuildTrree(n as integer)

...some code here

.. lnk = new LinkButton

lnk.CommandArgument = 2

AddHandler lnk.click,AddressOf click_event

...Add control to table here



End Sub

Publi sub click_event(............)

Buildtree(sender.commandArgument)

end Sub



The issue seems to be that control needs to be declared before it calls the
click event, as if I remove the Ispostback in the page load the event fires
but of course then the BuildTree is called more than once the output is
duplicated.

Can you tell me how organise the BuildTree call so that the linkbutton click
event fires.???

Thanks

Malcolm
 
G

Guest

It looks like when the postback occurs, the page gets regenerated. Which
means that all controls within the page also have to get re-generated.

Try playing with the PreRender event. It would be also a good idea to have
these links send back a postback value or a querystring (so the link becomes
something like page.aspx?linkid=<linkvalue>) and then catch that in Page Load
using the Request collection.

Tricky situation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top