ASP.NET: How to redirect, prefilling form data?

前端 未结 3 1792
孤城傲影
孤城傲影 2020-12-21 17:47

i want a handler to redirect to a web-forms page, pre-filling in the values of some controls on the form.

i tried setting my current Request.Form da

相关标签:
3条回答
  • 2020-12-21 18:13

    A few ideas that might get you started:

    1. Pass the values in the query string
    2. Store the values in the session state or in a seperate cookie
    3. Store the values in HttpContext.Items and use Server.Transfer instead of Response.Redirect
    0 讨论(0)
  • 2020-12-21 18:32

    You can only populate your Response, the Request is input data and is indeed read-only.

    If you are using ASP.NET, there are a variety of ways you could accomplish what you need:

    • The best way would probably be to pass the data you need to be pre-populated to SomeWebForm.aspx via the Session object, and on that pages Load method, populate your form. Keep in mind that when you do Response.Redirect, a 302 response is sent to the client with the URL the client should redirect to. The process is transparent to the user...but there is a full round trip involved.

    • Another alternative to populating the users Session would be to add GET parameters via a query string to the redirect to SomeWebForm.aspx.

    • If you need to transfer processing to the SomeWebForm.aspx page without round tripping, you could use Server.Transfer. This will transfer execution from the current page to the page you choose...however, this can cause some odd behavior on the client end because the URL does not update. As far as the user is concerned, it will still appear as though they are on the same page they started on.

    0 讨论(0)
  • 2020-12-21 18:37

    Another approach that hasn't been mentioned yet is using Server.Transfer makes it possible to use the Page.PreviousPage property, allowing access to the controls on the page that transferred control.

    As jrista mentioned though, using Transfer doesn't update the URL shown to the user, which may or may not be an issue. For example, a user can't precisely bookmark a page they got transferred to since the URL will be that of the original transferring page.

    0 讨论(0)
提交回复
热议问题