Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET - response.redirect passing data as a post

Posted on 2010-08-31
3
Medium Priority
?
633 Views
Last Modified: 2012-05-10
I've got a situation where I'm trying to post some data to a new page with a response.redirect.  I don't need to post the form that has the viewstate and all that, I just need to be able to specify a request redirect as a post and add custom data to it.  I've already got something like this running with javascript, as seen below, but in this case I would rather avoid using this method as the way I would need to implement it would be to register a script to the page to call the javascript method.  It seems like it would be a much better solution if I c could simply post to the new url without having to reload the original page.
function postURL(url) {

        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', url);

        var hiddenfield = document.createElement('input');
        hiddenfield.setAttribute('type', 'hidden');
        hiddenfield.setAttribute('name', 'history');
        hiddenfield.setAttribute('value', $('#<%= txtHistorySerialized.ClientID %>').val());

        form.appendChild(hiddenfield);
        document.body.appendChild(form);
        form.submit();
    }

Open in new window

0
Comment
Question by:josephdaviskcrm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
MlandaT earned 2000 total points
ID: 33572470
I think it's better you continue using your current method. It will perhaps be easier. You cannot POST in the way that you want. See here: http://www.west-wind.com/presentations/dotnetwebrequest/dotnetwebrequest.htm. You could alternatively use querystring: Response.Redirect("thePage.aspx?value=" & txtHistorySerialized.Text)

However, considering what you have there... where u are submitting to the same page.... neither of these new methods is best. Rather stick to what you doing if it's working.
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 33573990
try using server.transfer method
0
 

Author Comment

by:josephdaviskcrm
ID: 33577086
The problem with using the javascript method in this case is because it needs to be executed on the onclick event from a button on the page after some stuff has run on the server for that page.  So what ends up happening is that I do a postback on the button click and on the server I do a register script which runs the javascript method when the page reloads and forwards the user to the needed destination.  This is no good as it the user can see the page reload before they get forwarded.

Server.Transfer is not working as I would have hoped either.  It doesn't seem to be hanging on to the data that was posted previously.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question