473,396 Members | 1,891 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,396 software developers and data experts.

Class variable reverts to original value after event fires puzzler

Hello all,

I have a strange problem with a HtmlTable control, which is
dynamically created based on the results of a query.

Each row in the table has a LinkButton added to it. When I create the
LinkButton I also create a new Command event and set the command
argument to the primary key of the row in the database. I want every
link button I create to fire the same event, but I just need the
CommandArgument to be different:

private void buildHTMLTable()
{
foreach(DataRow row in drModList)
{
...
int intModID = Int32.Parse(drModList["mod_ID"].ToString());
// Sort out the link button
LinkButton lnkBtn = new LinkButton();
lnkBtn.Text = "Add detail";
lnkBtn.CommandArgument = intModID.ToString();
// Add the event
lnkBtn.Command += new CommandEventHandler(this.lnkBtn_Command);
...
}
}

I save the resulting generated table as a Session variable. Therefore
every time the page loads it checks to see if it already exists in the
Session object and if so, simply adds it to a placeholder.

When the user clicks on the button the event "lnkBtn_Command" fires as
expected, and the CommandArgument holds the correct primary key of the
row the user clicked, which is great.

I set the passed ID to a global variable "intSelectedModuleID" and
change the section the user is in by setting another global variable,
strCurrentSection, to a string "Edit Module".

private void lnkBtn_Command(object sender, CommandEventArgs e)
{
intSelectedModuleID = Int32.Parse(e.CommandArgument.ToString());
strCurrentSection = "Edit Module";
//Response.Write("Hello!");
}

This is where the problem lies... it appears that as soon as the
program exits this function the variables intSelectedModuleID and
strCurrentSection revert back to the values they held before the
function was called. It seems like the
changes to the variables are being undone for some reason. I assume
I'm missing a step when adding the events to the page dynamically, as
I change these variables all the time using VS.NET generated events.

The variables in question both have get and set methods and are
declared outside any functions at the top of the page:

public int intSelectedModuleID
{
get
{
try
{
return (int) ViewState["PDDmoduleSelectedIndex"];
}
catch
{
return 0;
}
}
set
{
ViewState["PDDmoduleSelectedIndex"] = value;
}
}

I really need to get this working before christmas so any help /
advice you could give me on this would be very much appreciated.

Oh one last thing.. for some reason I can't use the Response.Write
method in the "lnkBtn_Command" function. It crashes with the error
"Response is not available in this context". I hope that fixing one
problem will help the other!

Thank you in advance and have a very merry christmas.
Rob
Nov 15 '05 #1
0 1440

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

Similar topics

8
by: Tammy B. | last post by:
Hiya - Big puzzler for me. Code Below I create a class. I save it to a session variable. Then, I retrieve the session variable back into a new local variable. I am able to use a method which...
1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
8
by: downwitch | last post by:
Either I don't understand (entirely possible), or there's no way to copy parts of a class hierarchy from one instance to another. Say I have a class called Foo, and it contains, among other...
2
by: Warren Sarle | last post by:
The page http://warrensarle.com/temp.html has three lines of text. The top one is a p element saying "Not in a form", which is not in a form. The middle one is a button element saying "Button...
5
by: aamirghanchi | last post by:
Hi, I need to know if anyone else came across this. The Session variable value I set in a sortCommand event handler of a datagrid does not hold on till the next sortcommand event handler and...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
5
by: tshad | last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for each datatype of VB.Net (as well as C#). I am trying to set it up so that most of the work is done in the Abstract...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
1
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a class that Form1 calls to do some work. I would like to report back progress from the class to a richtextbox, will call it m_report, on the form. Like in the class, Form1.m_report.Text=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.