Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What is the VB.NET (or C#) code to prepare POST data and send to a different website than specified in the current <form ...> section?

EDIT: Every algorithm I've found online using HttpWebRequest gets the returning page from the other site and outputs it with Response.Write. I want to navigate to the new page posting the data and leaving the current page completely.

EDIT2: (more specific description of what I want) The code below displays a line chart. When the user clicks on the label for a data point, the page refreshes (performs a postback) and displaying the x-value of the clicked point.

Instead, upon clicking a label, I want to send other_id="#VALX" as the only POST data to other_results.aspx as if the user had typed the corresponding id into the the TextBox on other_search.aspx and clicked Submit.

How can I do that?

<%@ Page Language="VB" AutoEventWireup="true" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<%@ Import Namespace="System.Data.OracleClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Protected Sub Chart1_Click(sender As Object, e As System.Web.UI.WebControls.ImageMapEventArgs)
        Response.Write(e.PostBackValue)
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>My Title</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Chart ID="Chart1" runat="server" OnClick="Chart1_Click"
            DataSourceID="myDataSource">
            <Series>
                <asp:Series Name="Series1" ChartType="Line"
                    IsValueShownAsLabel="true" XValueMember="id"
                    YValueMembers="value" PostBackValue="#VALX" />
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" />
            </ChartAreas>
        </asp:Chart>
        <asp:SqlDataSource ID="myDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:myConnStr %>"
            ProviderName="<%$ ConnectionStrings:myConnStr.ProviderName %>"
            SelectCommand="SELECT id, value FROM myTable"
            DataSourceMode="DataReader"/>
    </div>
    </form>
</body>
</html>
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

If you need to send a POST request from your C#/VB.NET page to another website you want to take a look at the HttpWebRequest Class.

share|improve this answer
add comment
<form action="someotherwebsite/someotherform">
.....
</form>

In other words, just create a standard html form. Don't include the 'runat="server"' in the Form tag, and it will be treated as a standard html form. You CAN have more than one Form tag in an apsx page. You can only have one with runat="Server" set, but you can have other forms on your page, so long as they are not nested.

Edit

However, if you need to do some server-side processing of your own and you want to send the post data in addtition to the work YOU need to do server-side, then you can call the other site's form using the WebRequest class (as @Chris Pebble said, when he beat me to the second part of my intended answer.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.3.7.1431\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nosc"], "copyright__copyright__copyright": ["-side processing of your own and you want to send the post data in addtition to the work YOU need to do server-side, then you can call the other site's form using the WebRequest class (as @Chris Pebble said, when he beat me to the second part of my intended answer.)\n\nshare|improve this answer\nadd comment\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}