User Control and dynamic LinkButton problem

F

Fueled

Hi everyone!
I've made quite a lot of research on this, and I've tried a couple of
proposed solutions. Nothing has worked for me, but I feel there's not
much I'm missing. So I'm turning to this group and its experts for
answers.

So :
- I've got a main page (main.aspx)
- On this page, I've got a button (btnArchive), on whose click I
dynamically add a UserControl (archive.ascx) to the main page.
- Now on the PageLoad of the UserControl, I dynamically add several
LinkButtons.

- My dilemma lies here : on the click of one of these LinkButtons, I
wish to tell the main page to load a different UserControl (depending
on which LinkButton was clicked).

Thus, I imagine I need the LinkButtons to raise an event on the main
form and somehow pass the LinkButton's ID to the raised event, in order
to process the right UserControl load.

Hope I've been clear on this one. If anyone could help me with this,
I'd greatly appreciate. I could also post some sample code if it could
help.
Also, I'm programming in VB.NET, but I don't mind anyone anwsering with
C# ; I'll figure the translation.

Thanks and good day!
Simon.
 
S

S. Justin Gengo

Simon,

The button's are already notifying the main page that they were clicked with
something called a bubble event. You may override the OnBubbleEvent within
the main page to see which button(s) in a control are being clicked:

I have some sample code on my website
http://www.aboutfortunate.com/default.aspx?page=codelibrary

That shows how to use the OnBubbleEvent. Just use the search box on the page
above to search for "OnBubbleEvent" and you'll have the code you need.

If you have any other questions about it feel free to email me.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
F

Fueled

Thank you Justin for this piece of code, I bet it'll be useful.

I created the Overrides OnBubbleEvent function, and it fires fine from
the button on the Main page (btnArchive) and I'm able to get the
button's ID.
But it still does not fire from the LinkButton's click on the
UserControl. I don't know what could be the problem.

Here's how I create and add my LinkButton (it's added to a TD in a
table, during the UserControl's PageLoad) :

'===================================
Dim tdLbComposer As New LinkButton

tdLbComposer.ID = "lbComposer"
tdLbComposer.Text = "Beethoven"
tdComposers.Controls.Add(tdLbComposer)
'===================================

Is it possible that the LinkButton control doesn't fire this event?
Because I've tried adding a simple Button on the UserControl, and its
click does fire the event! I'll make some inquiring on this matter.
Thanks,
Simon.
 
S

S. Justin Gengo

Simon,

Controls added dynamically need to be recreated on post back for their
events to fire.

I have some sample code for dynamically adding controls on my website in the
code library. If you do a search for "dynamic controls" those examples may
help you.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
F

Fueled

Thanks again for your response.

You see, the thing is that even a LinkButton created at design-time
does NOT fire the OnBubbleEvent, and more so, a Button created
dynamically DOES fire the event!

So I don't see why reloading would be useful here, since dynamic Button
controls do fire the events.
I juste need to find out what's particular with the LinkButton control.

Thanks anyway!
Simon.


S. Justin Gengo a écrit :
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top