Missing the obvious...

S

SimeonArgus

Okay. I have the following situation. It is a basic case where a
dynamic button needs to remove itself after an action, and handle some
minor database flags.

public partial class ReportFrame : System.Web.UI.Page
{
DBConnection DB;

//protected void Page_Load(object sender, EventArgs e)
protected void Page_Init(object sender, EventArgs e)
{
// Okay, let's do some cleanup here.
DB = GeneralTools1.DB;
}

protected void Page_Load(object sender, EventArgs e)
{
foreach (string S in DB.GetNextRow())
{
Button B = new Button();
B.Text = S;
B.Click +=new EventHandler(B_Click);
MyPanel.Controls.Add(B);
}
}

protected void B_Click(object sender, EventArgs e)
{
Button B = (Button)sender;

// Do some SQL Stuff here to tell the database that B.Text has
been removed.
DB.DisableButton(B.Text);
}
}

PageLoad looks to see what buttons are "enabled" in the database. The
problem? B_Click happens AFTER PageLoad. Is there any way to do this
simple routine that I am over looking? This is a stripped down case,
In reality, the button click does alot with what is visible, etc.
However, this should get the gist of it in a simple-to-read version.
 
G

Guest

In Page load check to see if your event is triggered by a page PostBack.
Check to disable buttons only if you're not in a postback.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
foreach (string S in DB.GetNextRow())
{
....
}
}
}

HTH
 
S

SimeonArgus

In Page load check to see if your event is triggered by a page PostBack.
Check to disable buttons only if you're not in a postback.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
foreach (string S in DB.GetNextRow())
{
....
}
}

}

HTH

--
_________________________
Kostas Pantos [MCP]http://kostas.pantos.name

SimeonArgus said:
Okay. I have the following situation. It is a basic case where a
dynamic button needs to remove itself after an action, and handle some
minor database flags.
public partial class ReportFrame : System.Web.UI.Page
{
DBConnection DB;
//protected void Page_Load(object sender, EventArgs e)
protected void Page_Init(object sender, EventArgs e)
{
// Okay, let's do some cleanup here.
DB = GeneralTools1.DB;
}
protected void Page_Load(object sender, EventArgs e)
{
foreach (string S in DB.GetNextRow())
{
Button B = new Button();
B.Text = S;
B.Click +=new EventHandler(B_Click);
MyPanel.Controls.Add(B);
}
}
protected void B_Click(object sender, EventArgs e)
{
Button B = (Button)sender;
// Do some SQL Stuff here to tell the database that B.Text has
been removed.
DB.DisableButton(B.Text);
}
}
PageLoad looks to see what buttons are "enabled" in the database. The
problem? B_Click happens AFTER PageLoad. Is there any way to do this
simple routine that I am over looking? This is a stripped down case,
In reality, the button click does alot with what is visible, etc.
However, this should get the gist of it in a simple-to-read version.


Yes. But this *IS* a postback. That's the problem. My question is,
when I click on eof these buttons, and the page tries to redraw, is
there a simple step I am missing?? Surely it isn't this complicated...
right?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You have to add the button to the page in Page_Load, otherwise it will
not be able to handle the event. If you want to remove the button after
that, you just have to remove it from the page. Settings the Visible
property to false will keep it from being rendered to the page.
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top