I want to serialize all my output of a Web Form (from aspx and aspx.cs, on .NET 3.5) to JSON. So, this is my code :
protected string myText;
protected void Page_Load(object sender, EventArgs e)
{
myText = "<div><span>This is my whole code</span><div><a style=\"color:blue !important;\" href=\"#\">A link</a></div></div>";
}
protected internal override void Render(HtmlTextWriter writer)
{
var serializer = new JavaScriptSerializer();
Response.Write(Request["callback"] + serializer.Serialize(writer.ToString()));
}
but I get this error :
CS0507: 'moduli_Prova.Render(System.Web.UI.HtmlTextWriter)': cannot change access modifiers when overriding 'protected' inherited member 'System.Web.UI.Control.Render(System.Web.UI.HtmlTextWriter)'
Where am I wrong? Is this the right method to doing it?
I don't think you have
internal
on a overrideReference here
Maybe something like this:
Edit
We know that all pages inherit from
page
.. We also know that a newhtmltextwriter
take in astringwriter
that has astringbuilder
in the contructor. When we then call the base class (page
) to render the html to our newHtmlTextWriter
. It render it too thehtmltextwriter
that also renders to thestringbuilder
. So now we have the html context in ourstringbuilder
. Then we just say to the inputedHtmlTextWriter
that is should write thestring
from ourstringbuilder
.Reference here