473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

tough asp.net viewstate problem

krs
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+Oz4 7bDx0PDtsPGk8MT47PjtsPHQ8O2w

8aTwwPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47aTwzP jtpPDU+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

Jul 22 '05 #1
1 1326
Hi if you use
<form name="output" method="post" action="output.aspx" id="output"> for
posting to another
page ,you cant use server controls..Only normal html controls u can use.

"krs" wrote:
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+Oz4 7bDx0PDtsPGk8MT47PjtsPHQ8O2w

8aTwwPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MT47aTwzP jtpPDU+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

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like this in the aspx:
1
by: krs | last post by:
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...
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.