Object Creation.

G

Guest

Hi All,
I have this basic doubt.
Consider the following piece of code

class MyClass
{
XmlDocument objXmlDoc;
void page_load ()
{
if ( ! IsPostBack )
{
objXmlDoc = new XmlDocument ( );
}
}
}

Now my doubt is whenever the page is refreshed, is a new object created, I
mean to say is the statement XmlDocument objXmlDoc executed every time I
refresh or just the page_load function is executed.

Expecting replies at the earliest.

Thanks
GS.
 
T

tdavisjr

Your object is created once when the page first loads. After that,
anytime the page reloads as a result of a postback your object will be
null. So, you need to persist that object somewhere if you need a
reference to it in some other method. Maybe use session state since the
XmlDocument is Serializable.
 
G

Guest

But here I am talking about the refresh of a page.
What I mean to ask was is the object of myclass created everytime I refresh
manually a page... I am not talking about an Auto refresh, or a page reload.
 
T

tdavisjr

Yes. It is created everytime you manually refresh the page. The only
time it doesn't get created is if the page was reloaded as a result of
a postback caused by a control. Hope I answered it. You may want to
set a breakpoint in your code to test this yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top