So I understand the basics of the prg pattern. But I haven\'t come across a technique for making arbitrary data available to the \"get\" instance of a page.
For exa
I think you can still use the get method in the form element. In this case you won't be able to use the ID of your control in normal way. But you can use the Request.Params collection to get the viewstate.
Update: Sorry, I just tried again. and found that you can access your server control by its ID in codebehind. like:
Response.Write(text1.Text)
see the example:
the aspx page(only the form element):
< form id="form1" runat="server" method="get">
< div>
< asp:TextBox ID="text1" runat="server" />
< asp:Button ID="button1" runat="server" OnClick="buttonClick" />
< div>
< form>
NOTE: I used a space before each" <" otherwise the code above will not be visible.
the code behind page (only button click event):
protected void buttonClick(object sender, EventArgs e)
{
string text = Request.Params["text1"];
Response.Write(text);
}
when you click the button the url will look like this:
http://localhost:1157/WebSite1/Default.aspx?__VIEWSTATE=%2FwEPDwUKMTkwNjc4NTIwMWRkoJEtEHZ8lHQ53QllSkz8ncpEw80%3D&__EVENTVALIDATION=%2FwEWAwKf%2BPPUCwKTjKGwCgKs34rGBvus9oxN%2FQkHlkzpKUEwrbxHLM6u&text1=ashish&button1=
If the fields POSTed are being persisted before the Redirect and you need to access that data after the Redirect, I would append the identifier for the data record(s) on the query string as you mention. You could also specify a status for the request (for displaying messages etc). Then on the GET page you can read out the data and do whatever with it.
I don't see any other way to get around this as each page obtained by GET will not have access to the previous page's ViewState
etc.
Using Server.Transfer
will have the same effect as handling the POST on the original page.
You could use Session variables to store the POST data, but that stinks.