473,403 Members | 2,323 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,403 software developers and data experts.

Where do I initialize?

I'm working on a UserControl ( ASP.NET 1.1, C#, VS 2003), where I can't
manage the state of multiple controls correctly.

The controls have the following constraints

1: It has two possible appearances: One 25px high ( InActiveState) with
just a summary & an 'Activate / DeActivate' button, or the complete (400px)
high (Active) control
2: Only one control can be active on a page at any given time.

My problem is that my logic doesn't work ( or, why else would I be posting
this).
I have a test container with 3+ controls on it. I activate the first
control just fine. When I activate the second control, it appears but the
first control doesn't de-activate. When I activate the third control, the
first two deactivate. I then activate one of the first two, and the third
doesn't deactivate. When I activate another, the two previously active
controls deactivate. I'm wondering if I should move some of the following
logic to the Page_Unload method, or to the Initialize or PreRender methods.

My existing logic is as follows:

I am handling this using Session Variables, all defined/modified in the
Page_Load or the btnActivate_DeActivate_Click methods of the MyControl
class.
I create a Session variable for each control: Session[ this.ClientId +
"_ActiveState" ] , = "1" for the active state, "0" otherwise,
and one session variable to indicate which control is active: Session[
"WhichControlIsActive" ] = this.ClientId
of the currently active control

In MyControl
Page_Load
{
if ( Session[this.ClientId + "_ActiveState"] == null ) Session[
this.ClientId + "_ActiveState"] = "0"; // Initialize null session
variable for active state to inactive
if ( Session[ "WhichControlIsActive" ] == null ) Session[
"WhichControlIsActive" ] == "None"; // Initialize null session
variable for active control to none

if ( (Session[this.ClientId + "_ActiveState"] == "0") || (
Session["WhichControlIsActive" ] != this.ClientId)) // this control is
inactive
{
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[this.ClientId + "_ActiveState] == "0" ;
}
if ( ( Session[this.ClientId + "_ActiveState] == "1") && (
Session["WhichControlIsActive" ] == this.ClientID) ) // this control
is active
{
SetHeight( this, 400);
this.btnActivateDeAtivate.text = "De Activate";
}

}

btnActivateDeActivate_Click( .... )
{
// Determine whether to Activate or Deactivate the control
if ( Session[ "WhichControlIsActive" ] == this.ClientID
// This was the active control, so deactivate it
{
Session[ this.ClientID + "_ActiveState" ] = "0";
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[ "WhichControlIsActive" ] = "None";
// I just deactivated the active control, so no control is active
Session[ this.ClientID + "_ActiveState" ] = "0";
// Set this controls session variable of active state to "0"
DoTheRestOfMyStuff( .. );

}
else // This control is
newly the active control
{
Session[ this.ClientID + "_ActiveState" ] = "1"
// Set this control's session variable to "1";
Session[ "WhichControlIsActive " ] = this.ClientID;
// Set the 'Global' session variable to this control
SetHeight( this, 400);
this.btnActivateDeActivate.text = "De Activate";
}
}
Any Suggestions?

Thanks


Mar 1 '06 #1
2 2281
DWS
Phillip,

pre_render

Good Luck
DWS

"Phillip N Rounds" wrote:
I'm working on a UserControl ( ASP.NET 1.1, C#, VS 2003), where I can't
manage the state of multiple controls correctly.

The controls have the following constraints

1: It has two possible appearances: One 25px high ( InActiveState) with
just a summary & an 'Activate / DeActivate' button, or the complete (400px)
high (Active) control
2: Only one control can be active on a page at any given time.

My problem is that my logic doesn't work ( or, why else would I be posting
this).
I have a test container with 3+ controls on it. I activate the first
control just fine. When I activate the second control, it appears but the
first control doesn't de-activate. When I activate the third control, the
first two deactivate. I then activate one of the first two, and the third
doesn't deactivate. When I activate another, the two previously active
controls deactivate. I'm wondering if I should move some of the following
logic to the Page_Unload method, or to the Initialize or PreRender methods.

My existing logic is as follows:

I am handling this using Session Variables, all defined/modified in the
Page_Load or the btnActivate_DeActivate_Click methods of the MyControl
class.
I create a Session variable for each control: Session[ this.ClientId +
"_ActiveState" ] , = "1" for the active state, "0" otherwise,
and one session variable to indicate which control is active: Session[
"WhichControlIsActive" ] = this.ClientId
of the currently active control

In MyControl
Page_Load
{
if ( Session[this.ClientId + "_ActiveState"] == null ) Session[
this.ClientId + "_ActiveState"] = "0"; // Initialize null session
variable for active state to inactive
if ( Session[ "WhichControlIsActive" ] == null ) Session[
"WhichControlIsActive" ] == "None"; // Initialize null session
variable for active control to none

if ( (Session[this.ClientId + "_ActiveState"] == "0") || (
Session["WhichControlIsActive" ] != this.ClientId)) // this control is
inactive
{
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[this.ClientId + "_ActiveState] == "0" ;
}
if ( ( Session[this.ClientId + "_ActiveState] == "1") && (
Session["WhichControlIsActive" ] == this.ClientID) ) // this control
is active
{
SetHeight( this, 400);
this.btnActivateDeAtivate.text = "De Activate";
}

}

btnActivateDeActivate_Click( .... )
{
// Determine whether to Activate or Deactivate the control
if ( Session[ "WhichControlIsActive" ] == this.ClientID
// This was the active control, so deactivate it
{
Session[ this.ClientID + "_ActiveState" ] = "0";
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[ "WhichControlIsActive" ] = "None";
// I just deactivated the active control, so no control is active
Session[ this.ClientID + "_ActiveState" ] = "0";
// Set this controls session variable of active state to "0"
DoTheRestOfMyStuff( .. );

}
else // This control is
newly the active control
{
Session[ this.ClientID + "_ActiveState" ] = "1"
// Set this control's session variable to "1";
Session[ "WhichControlIsActive " ] = this.ClientID;
// Set the 'Global' session variable to this control
SetHeight( this, 400);
this.btnActivateDeActivate.text = "De Activate";
}
}
Any Suggestions?

Thanks


Mar 2 '06 #2
Thanks, that's where I ended up putting most of my logic.

I'm still not happy that I create approximately 200 controls in Page_Load
for each of 10 instances of my user control, then proceed to hide them in
Pre_Render in all but one instance, but that seems the best we can do. Some
other functionality took a lot of really kludgy workaround.

I still think it would be nice if there were some class of variables, e.g.
ImmediateSession["MyKey"], which would reflect actions from a previous
instance of a webform available in the Page_Load of the repost.

Thanks again

"DWS" <DW*@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
Phillip,

pre_render

Good Luck
DWS

"Phillip N Rounds" wrote:
I'm working on a UserControl ( ASP.NET 1.1, C#, VS 2003), where I can't
manage the state of multiple controls correctly.

The controls have the following constraints

1: It has two possible appearances: One 25px high ( InActiveState) with
just a summary & an 'Activate / DeActivate' button, or the complete
(400px)
high (Active) control
2: Only one control can be active on a page at any given time.

My problem is that my logic doesn't work ( or, why else would I be
posting
this).
I have a test container with 3+ controls on it. I activate the first
control just fine. When I activate the second control, it appears but
the
first control doesn't de-activate. When I activate the third control,
the
first two deactivate. I then activate one of the first two, and the
third
doesn't deactivate. When I activate another, the two previously active
controls deactivate. I'm wondering if I should move some of the
following
logic to the Page_Unload method, or to the Initialize or PreRender
methods.

My existing logic is as follows:

I am handling this using Session Variables, all defined/modified in the
Page_Load or the btnActivate_DeActivate_Click methods of the MyControl
class.
I create a Session variable for each control: Session[ this.ClientId +
"_ActiveState" ] , = "1" for the active state, "0" otherwise,
and one session variable to indicate which control is active: Session[
"WhichControlIsActive" ] = this.ClientId
of the currently active control

In MyControl
Page_Load
{
if ( Session[this.ClientId + "_ActiveState"] == null ) Session[
this.ClientId + "_ActiveState"] = "0"; // Initialize null session
variable for active state to inactive
if ( Session[ "WhichControlIsActive" ] == null ) Session[
"WhichControlIsActive" ] == "None"; // Initialize null session
variable for active control to none

if ( (Session[this.ClientId + "_ActiveState"] == "0") || (
Session["WhichControlIsActive" ] != this.ClientId)) // this control
is
inactive
{
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[this.ClientId + "_ActiveState] == "0" ;
}
if ( ( Session[this.ClientId + "_ActiveState] == "1") && (
Session["WhichControlIsActive" ] == this.ClientID) ) // this
control
is active
{
SetHeight( this, 400);
this.btnActivateDeAtivate.text = "De Activate";
}

}

btnActivateDeActivate_Click( .... )
{
// Determine whether to Activate or Deactivate the control
if ( Session[ "WhichControlIsActive" ] == this.ClientID
// This was the active control, so deactivate it
{
Session[ this.ClientID + "_ActiveState" ] = "0";
SetHeight( this, 25);
this.btnActivateDeActivate.text = "Activate";
Session[ "WhichControlIsActive" ] = "None";
// I just deactivated the active control, so no control is active
Session[ this.ClientID + "_ActiveState" ] = "0";
// Set this controls session variable of active state to "0"
DoTheRestOfMyStuff( .. );

}
else // This control
is
newly the active control
{
Session[ this.ClientID + "_ActiveState" ] = "1"
// Set this control's session variable to "1";
Session[ "WhichControlIsActive " ] = this.ClientID;
// Set the 'Global' session variable to this control
SetHeight( this, 400);
this.btnActivateDeActivate.text = "De Activate";
}
}
Any Suggestions?

Thanks


Mar 6 '06 #3

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

Similar topics

6
by: S. David Rose | last post by:
Hello All! I am new to Python, and wanted to know if I might ask you a question regarding timing. I want a main loop which takes photos from 8 different web-cams, each can be addressed by...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
6
by: MathewLovesC | last post by:
Can someone help me out here? I have a bunch of test statements in the program and my test printf("Do I have trouble here after GetNumbers()?\n"); does not display rather I get garbage. Please...
13
by: Thomas Zhu | last post by:
Hello, I know the difference between the two definations. But I do not know where are they in the memory. would someone tell me ? char s={"good", "morning"}; // at stack? char *t = {"good",...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
8
by: bryan | last post by:
I'm using the UIP App block and I have overridden the Initialize method, but my override never gets called. Here's the code: public override void Initialize(TaskArgumentsHolder args,...
6
by: Mr Flibble | last post by:
Hi all, I've decided to use log4net for my logging/tracing. In the example on the site it shows using main() to setup the root logger and then using the LogManager within your classes to...
3
by: MikeY | last post by:
Hi everyone, I'm having problems with my WHERE Clause syntax with in my SQL CommandText. The error that it is display is "You Have No Data". My problem lies with in the WHERE clause not finding...
14
by: Neviton | last post by:
Help with this error ! Please ! The code below is simplified, because I'm trying to solve this error. ....MyClass.cpp In member function `void MyClass::Initialize()': ....MyClass.cpp aggregate...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.