Object reference not set to an instance of an object

G

Guest

Hi,
I'm trying to create a page loading a XML file and declaring ASP.NET controls on an XSLT file.
the application is giving me the error "Object reference not set to an instance of an object" when i try to add an event handler (like button_click()) during the loading of the page.
How can I add the reference?
is it possible?
thank you
 
B

Ben Dewey

I am not exactly sure what you are asking. Can you please post you code?

The Object reference not set to an instance error usually occurs when a an
object is not set using the new keyword. For example when you try to use an
XmlDocument without setting the object equal to a "new XmlDocument()"

Fabrizio said:
Hi,
I'm trying to create a page loading a XML file and declaring ASP.NET controls on an XSLT file.
the application is giving me the error "Object reference not set to an
instance of an object" when i try to add an event handler (like
button_click()) during the loading of the page.
 
G

Guest

Sure
I created an xslt file where i add an ASP:dropdownlist list1
Then, onload of the page, i'm loading xml,xsl and searching for the control "list1"
when i try to refer to ddl control, is giving that awful messag
Let me know if you need xsl file
thank yo

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument()

xmlDoc.Load(Server.MapPath("XML/nuovo.xml"))


System.Xml.Xsl.XslTransform transform = new System.Xml.Xsl.XslTransform()

transform.Load(Server.MapPath("XML/again.xslt"))
XmlUrlResolver resolver = new XmlUrlResolver();

System.IO.StringWriter swriter = new StringWriter()


transform.Transform(xmlDoc, null, swriter, resolver)


Page.FindControl("Form1").Controls.Add(Page.ParseControl(swriter.ToString()))

swriter.Close()



////here comes the erro
ddl = (DropDownList)Page.FindControl("list1")

ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged)
 
B

Ben Dewey

I was able to add and find the control fine. your code looks good. Can you
send me the result of you StringWriter Transform Output.

The only way i was able to replicate you error is when I searched for a
control that wasn't actually there. Just make sure that you
StringWriter.ToString() is actually returning the list1 control.
 

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

Top