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
Solved

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

Posted on 2010-08-31
3
627 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 30

Accepted Solution

by:
MlandaT earned 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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