473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Missing the obvious...

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.

Mar 16 '07 #1
5 1099
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.

Mar 17 '07 #2
On Mar 17, 4:56 am, Konstantinos Pantos
<KonstantinosPan...@discussions.microsoft.comwrote :
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.

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?

Mar 17 '07 #3
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.

--
Göran Andersson
_____
http://www.guffa.com
Mar 18 '07 #4

More see here!

http://www.flash50.com/index.php
Mar 18 '07 #5
fy*****@gmail.com wrote:
More see here!

http://www.flash50.com/index.php
Nothing to see there. Stop spamming.

--
Göran Andersson
_____
http://www.guffa.com
Mar 18 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
1
by: Ctal | last post by:
Relatively new to dotnet so bear with me if this is obvious. In the course of my career, I've assembled a collection of icons to use with my apps. Most of these are 32x32, 256 or 16x16, 16. ...
1
by: Dominick Baier | last post by:
Hi, you are right - Windows needs the password in plaintext to impersonate a user (having to call LogonUser, which requires a password). Thinking about it - it is the only way Windows can do it. ...
0
by: JohnR | last post by:
Hi all.. my application uses a custom dll which should be in the same directory as the exe file. If the dll file is missing the application immediately aborts with a "Application has generated an...
2
by: Steven D'Aprano | last post by:
When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer("foo(x, y)", \ """from module import foo x = 27 y = 45 """) elapsed_time =...
77
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it,...
1
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the...
8
by: =?Utf-8?B?cDNqb2hu?= | last post by:
Hi all, Not sure if this is the correct newsgroup for this, but I'm in a jamb and need some input. I came across a problem that I think is related to the C# compiler in Visual Studio 2008. The...
9
by: Boltar | last post by:
On 32 bit linux with gcc 4.2 I get unexpected results with this code: main() { int bits = 32; printf("%d\n",(int)1 << (int)32); printf("%d\n",(int)1 << bits); }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.