I want to during the page render remove some html from the page (don’t ask why).
protected override void Render(HtmlTextWriter writer)
{
MemoryStream memoryStream = new MemoryStream();
try
{
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
var textWriter = new HtmlTextWriter(streamWriter);
base.Render(textWriter);
textWriter.Flush();
memoryStream.Position = 0;
using (StreamReader reader = new StreamReader(memoryStream))
{
var text = reader.ReadToEnd();
Regex r = new Regex("<option .+?</option>");
text = r.Replace(text, "");
writer.Write(text);
reader.Close();
}
}
}
catch (ObjectDisposedException)
{
}
finally
{
memoryStream.Dispose();
}
}
Unfortunatelly I’ve got the PageRequestManagerParserErrorException exception from the update panel located on this page. How can I achieve the result I want without getting the error?
Solution was to create a custom control which derived from GridView in this example and used this code in the Render method of this control, not on the page where control is used.