Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now