Solved

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

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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