470,855 Members | 2,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Global variable lost in Change event Handler?

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">

it appears on the web page as


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">

(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.)

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
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

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 1676

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sandman | last post: by
2 posts views Thread by Bela | last post: by
5 posts views Thread by aamirghanchi | last post: by
3 posts views Thread by thomson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.