Catch-22 in Web Application

  • Thread starter Thread starter SimeonArgus
  • Start date Start date
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?

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

--Sim
 
Here is the code that I am using to build this page.

public partial class ReportFrame : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DBConnection DB = GeneralTools1.DB;

// Query Truck Details
LoadTrucks();

<SNIP>

// If I run these here, they won't have the right info from
the DB since the button clicks haven't
// happened yet. However, the buttons that ARE created are
work as expected.
//BuildUnscheduled();
//BuildScheduled();

// Build Truck List
// MapPoints

}

protected void Page_PreRender(object sender, EventArgs e)
{
// If I put these here, the buttons display properly becuase
they pull valid data from the DB.
// but their onClick events won't fire.
BuildUnscheduled();
BuildScheduled();
}

private void BuildScheduled()
{
DBConnection DB = GeneralTools1.DB;

string SQL = "SELECT * FROM CC_MapControl_Order a,
CC_MapControl_Client b WHERE " +
" a.ClientID = b.ClientID ORDER BY ReqTime ASC";

<SNIP for each item in MapControl_Order>

ImageButton b = new ImageButton();
b.ImageUrl = "../images/list-remove_sm.png";
b.Width = 12;
b.Height = 12;
b.ID = DB.GetValue("OrderID") + "_RemOrder";
b.Click += new ImageClickEventHandler(b_Click);

Box.Controls.Add(b);
}
}
 
Hi Sim,

what about this:
always create all buttons in the FormLoad-event, then make them
visible/invisible in the PreRender-event.

HTH
Christof
 

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

Back
Top