473,396 Members | 1,783 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.

Global variable lost in Change event Handler?

BACKGROUND
----------
I have an ASP.NET application having two panels. In one panel, an XML
document, transformed using xsl, is displayed. In the other panel are some
controls that allow a user to change the xml. For example, each "l_item"
element appears as a row in a table labelled with a "label"; so if I have

<l_item id="1">
<label>blah</label>
...
</l_item>

it appears on the web page as

-------------
BLAH:
...
-------------

In the other panel there is a textbox control, where the user can type a new
label and click a button, causing the xml document to change and thus the
display to change.

If a "l_item" has been changed from the original xml, I want the attribute
for that item to change. Using the above example if the user changed the
label to "blahblah" I want the xml to look like this:

<l_item id="-1">
<label>blahblah</label>
...
</l_item>

(When the user is finished, the document is sent to a database procedure
that only bothers to update records where the id is a negative number.)

CODING
------
Without going into too much detail, I have methods that change the xml
document in response to the control values and a XmlNodeChangedEventHandler
that changes the "l_item".

...//global variables
Protected selected As String
Protected selectednode As XmlNode
...

(In Page_Load)
...
A selected = Request.Form("selectedrow")
B selectednode =
xmlegend.DocumentElement.SelectSingleNode("//l_item/label='" & selected &
"']")
...

(In the label text box method)
...
C If selectednode Is Nothing Then Exit Sub
Try
D selectednode.Item("label").InnerText = label_txt.Text
Catch ex As Exception
E emessage = ex.Message
...

(In the node change handler)
If (args.Action = XmlNodeChangedAction.Change And args.Node.LocalName
<> "id") Then
F coi = selectednode.Attributes.Item(0).InnerText
If Not (coi.StartsWith("-")) Then
selectednode.Attributes.Item(0).InnerText = "-" & coi
End If
End If

PROBLEM
-------
Line F throws a "Object reference not set to an instance of an object"
exception. When debugging using VS, the debugger shows that when the page
reloads after changing the label text box, "selected" is set to the correct
value at line A and that "selectednode" becomes a valid XMLElement at line B.
At lines C and D, the debugger shows these values are still there. Flow
branches to the node change handler, coming to line F as it should. But the
debugger shows that at line F both "selected" and "selectednode" are
"Nothing". Flow goes back to the exception handler, line E, which shows
"selected" and "selectednode" are the same legitimate values they were before.
So somehow, the node change handler doesn't see the global variable values.
How can I get this to work?

Many thanks.
Nov 12 '05 #1
0 1813

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

Similar topics

8
by: Fred Basset | last post by:
I am modifying existing code to add modal functionality to an IE5+ ActiveX Web-App. What I am trying to achieve is simple modal behaviour on popup windows, apart from certain specified ones. I...
1
by: Sandman | last post by:
Below you find a small test page. I contains an input box, with an onBlur event, and a form, with an onSubmit event. When I place the cursor in the text box and push ENTER, first the onBlur...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
2
by: Bela | last post by:
Hello I was wondering if someone could help me out with a Session_End problem in my Global.asax. I've tried everything, and still no success Here is the scenario: sessionstate is set to InProc....
4
by: Marc Missire | last post by:
Hi, I have an issue below I'd love help with, involving a static variable, Application_Start, and a background thread. In global.asax.cs I have a static variable (outside any method) with a...
3
by: kingski | last post by:
I have a web site created with ASP.NET 1.1. availability Global.asax: protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
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...
3
by: thomson | last post by:
Hi All, i do have an website with the URL http://localhost/application/ASEAN-ANZ, Once i hit the application, it goes to the Global.asax. but after that if i tried to change the URL...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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
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,...

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.