G
Guest
Right, third time lucky, I'll try and explain this with some code examples:
The general theory here is build a dynamic aspx page, render the output to
an .aspx file that is then saved, this is the publised file. Imagine a Web
Content Management type
scenario.
pageA.aspx -
// generate the page output and save it to a output.aspx
// this is the published file that non admin users will see when browsing
the site
// A main reason for doing this is to save all the processing on each visit,
the users
// just see a published page, rather than a dynamically built one on each
visit.
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htmlTR = new HtmlTextWriter(sw);
base.Render(htmlTR);
string filename = (string)Server.MapPath("readonly.aspx");
StreamWriter sr = new StreamWriter(filename, false, Encoding.UTF8);
sr.WriteLine(sb.ToString());
sr.Close();
}
output.aspx -
<html>
<head>
<title>output</title>
</head>
<body>
<form name="output" method="post" action="pageA.aspx?pageId=1"
id="output">
<input type="hidden" name="__VIEWSTATE"
value="dDw1MzgxO3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47PjtsPHQ8O2w
8aTwwPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47aTwzPjtpPDU+O2k8Nz47aTw5Pjs+>
<input name="Name" type="text" id="Name" />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
The problem is that because I'm saving the rendered pageA.aspx to a file
called output.aspx, the action/viewstate within the file is wrong.
If I then post a form on output.aspx it tries to post to pageA.aspx. I can
get around this and change the form action before I output the file to read:
<form name="output" method="post" action="output.aspx" id="output">
but this seems to result in viewstate not being restored to the form values.
Any ideas greatly appreciated.
Thanks
Kieran
The general theory here is build a dynamic aspx page, render the output to
an .aspx file that is then saved, this is the publised file. Imagine a Web
Content Management type
scenario.
pageA.aspx -
// generate the page output and save it to a output.aspx
// this is the published file that non admin users will see when browsing
the site
// A main reason for doing this is to save all the processing on each visit,
the users
// just see a published page, rather than a dynamically built one on each
visit.
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htmlTR = new HtmlTextWriter(sw);
base.Render(htmlTR);
string filename = (string)Server.MapPath("readonly.aspx");
StreamWriter sr = new StreamWriter(filename, false, Encoding.UTF8);
sr.WriteLine(sb.ToString());
sr.Close();
}
output.aspx -
<html>
<head>
<title>output</title>
</head>
<body>
<form name="output" method="post" action="pageA.aspx?pageId=1"
id="output">
<input type="hidden" name="__VIEWSTATE"
value="dDw1MzgxO3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47PjtsPHQ8O2w
8aTwwPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47aTwzPjtpPDU+O2k8Nz47aTw5Pjs+>
<input name="Name" type="text" id="Name" />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
The problem is that because I'm saving the rendered pageA.aspx to a file
called output.aspx, the action/viewstate within the file is wrong.
If I then post a form on output.aspx it tries to post to pageA.aspx. I can
get around this and change the form action before I output the file to read:
<form name="output" method="post" action="output.aspx" id="output">
but this seems to result in viewstate not being restored to the form values.
Any ideas greatly appreciated.
Thanks
Kieran