Catch-22 with Web Application

S

SimeonArgus

I have a situation that I can't seem to work around. I have a database
that lists the buttons that my application should generate. These
buttons are displayed if certain conditions are met and all previous
button clicks make sense. Sounds simple, right?

Here's the catch. C# Processes FormLoad first, then Button Clicks, so
if I build the page in FormLoad, the wrong buttons may appear, because
the "hide the green buttons" click hasn't been processed to the
database yet.

So I thought about rendering the buttons in PageRender. That runs
after the button clicks have been processed. But when I create the
buttons here, C# doesn't seem to register the button on_click events
with the buttons any more. So it will generate the right buttons, but
clicking them has no effect.

Is there a function, like PageLoad that will always run, but run AFTER
button clicks have been processed, but still will allow me to create
the dynamic button, including a dynamic onClick event?

If not, is there a workaround?

I know it sounds silly, but any direction would be very appreciated!

--Sim
 
M

Mark Rae

I know it sounds silly, but any direction would be very appreciated!

Are we talking about an infinite number of buttons here, or is there a
fairly small maximum number which could ever be displayed...?

If the latter, just create them all on the page as normal but set them their
Visible property to "false" by default. Then, on your postback, set their
Visible property to "true" as required...
 
S

SimeonArgus

Are we talking about an infinite number of buttons here, or is there a
fairly small maximum number which could ever be displayed...?

If the latter, just create them all on the page as normal but set them their
Visible property to "false" by default. Then, on your postback, set their
Visible property to "true" as required...

Thank you for the response. I have done something similar, but it is
technically infinite (although __probably__ never more than 20)

I think it a bit problematic to build 20 buttons if I only plan on
using 2. And in the case when (someday) I need 21, I've got to
rearchitect and add a couple more. As my boss would say "How much is
not enough-plus-one?" =(

Another problem is that the order of the buttons changes, and if I
build the buttons (and place them) then I can't move them later. And
I've already tried assigning them to a TableRow object, and then
placing the table row into the appropriate table later. Again, the
button OnClick never fires. =( I'm REALLY getting frustrated with
this.

This problem has kept me back for three days, for a problem that
shouldn't take more than an hour or two to fix, if one knew how to get
around it. Obviously, I dont. =)

Any other suggestions?? I'm hoping that this is just another example
of my moronic-ness. It really can't be this hard, right???
 
M

Mark Rae

Any other suggestions??

Hmm - OK, I see the dilemma...

I have two possible suggestions:

1) Could you have a hidden field on your form and use the button's
OnClientClick method to write a value to it which could, in turn, be
interrogated in the page's postback...? This would allow you to create the
dynamic buttons in the page's Page_Init method, which would mean that their
events would get wired up correctly... This is a horrible, horrible kludge,
though...

2) Could you use an <asp:Repeater>? I'm thinking you possibly couldn't
because you mentioned that the dynamic buttons need to be positioned in
different places...
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top