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.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" wrote:
> 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.
>
On Mar 17, 4:56 am, Konstantinos Pantos
<KonstantinosPan...@.discussions.microsoft.com> wrote:
> 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" wrote:
>
>
>
>
>
>
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?
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.
SimeonArgus wrote:
> 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.
>
Gran Andersson
_____
http://www.guffa.com
fy4.net@.gmail.com wrote:
> More see here!
> http://www.flash50.com/index.php
>
Nothing to see there. Stop spamming.
Gran Andersson
_____
http://www.guffa.com
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment