Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-31
3
Medium Priority
?
635 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
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

885 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