472,993 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 1793

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: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.