Error as execute response.End on a page with masterPage (VS2

Im trying to implement your grid in VS2005, and it seems to work fine. The page is not part of a master page. The same code placed on a page using MasterPage does not work. I get the following error:



{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}



The errors triggers when executed the sentence Response.End int the code below.



Any help would be greatly appreciated!!





protected void createXmlForGrid(System.Xml.XPath.XPathNavigator nav)

{

Response.AddHeader(“Content-type”, “text/xml”);



Int16 index = 1;

XmlWriter wr = XmlWriter.Create(Response.OutputStream);

XPathExpression exp;

XPathNodeIterator iterator;

exp = nav.Compile(“rows/item”);

iterator = nav.Select(exp);



wr.WriteStartElement(“rows”);



while (iterator.MoveNext())

{



//-- Número de fila

wr.WriteStartElement(“row”);

wr.WriteStartAttribute(“id”);

wr.WriteString(index.ToString());

wr.WriteEndAttribute();



//-- registros de la fila

wr.WriteStartElement(“cell”);

wr.WriteString(index.ToString());

wr.WriteEndElement();



createNewNode(iterator, wr, “@idproduct”)

createNewNode(iterator, wr, “@idorigin”)

createNewNode(iterator, wr, “@deliverydate”)



//-- Numero de fila

wr.WriteEndElement();



index += 1;

}



wr.WriteEndElement();

wr.Close();



Response.End();





}



private void createNewNode(XPathNodeIterator iterator, XmlWriter wr, string xmlField)

{

if ((iterator.Current.SelectSingleNode(xmlField) != null))

{

wr.WriteStartElement(“cell”);

wr.WriteString(iterator.Current.SelectSingleNode(xmlField).InnerXml);

wr.WriteEndElement();

}

}



I’m not sure, but it seems that your code generates data XML and sends it back, while it fully correct it can’t be included as part of default HTML form, because they generate fully separated content, that is why .NET show described error.

The problem is outside of component, so unfortunately I can’t help you ( it seems for me that such pages, which generates non-html content must not be included as parts of other pages, but my knowledge in .Net area are far from perfect )