Using PostBackUrl To Post Form Data To a php Page

by Saurabh 31. March 2006 16:59

Many Windows Server 2003/IIS 6 Web hosts provide php & Perl among other goodies. And if you happen to be among the rare people who work on both Microsoft .net & LAMP technologies like me ;) you must absolutely adore this new cool capability in ASP.net 2.0 that allows you to post data to a php/Perl page. Though you can literally post to a page written in any language using the technique, I'm focusing on a specific example illustrating the ability to post form data to a php page using ASP.net 2.0.
Note:  I am talking about sending form data using the POST method, not by appending anything to the URI.
Say you have this basic page with a simple form.

   1: <%@ Page Language="C#" %>
   2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   3: <script runat="server">
   4: protected void Button1_Click(object sender, System.EventArgs e)
   5: {
   6: Label1.Text = "Hello " + TextBox1.Text + "<br />" + "Date Selected: " + Calendar1.SelectedDate.ToShortDateString();
   7: }
   8: </script>
   9: <html xmlns="http://www.w3.org/1999/xhtml" >
  10: <head runat="server">
  11: <title>Cross Page Posting</title>
  12: </head>
  13: <body>
  14: <form id="form1" runat="server">
  15: <div>
  16: Enter your name: <br />
  17: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  18: <p>
  19: When do you want to fly?<br />
  20: <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
  21: </p>
  22: <br />
  23: <asp:Button ID="Button1" runat="server" Text="Post2Self" OnClick="Button1_Click" />
  24: &nbsp;&nbsp;
  25: <asp:Button ID="Button2" runat="server" Text="Post2php" PostBackUrl="PostBackAcceptor.php" />
  26: <p>
  27: <asp:Label ID="Label1" runat="server"></asp:Label>
  28: </p>
  29: </div>
  30: </form>
  31: </body>
  32: </html>

So now we can have a simple php page that can dump POST data as output, like this…

   1: <?php
   2: echo '$_POST["TextBox1"]';
   3: echo " &raquo; ";
   4: echo '$_POST["TextBox1"]';
   5: echo "<br />";
   6: echo '$_POST["Button2"]';
   7: echo " &raquo; ";
   8: echo '$_POST["Button2"]';
   9: ?>

The output we get; should be obvious to people who know both php & ASP.net ;)

$_POST["TextBox1"] raquo; Chad
$_POST["Button2"] raquo; Post2php

Though some people might say there's no reason to do this considering the explosion of web services in our Web 2.0 era. But there are a number of scenarios where this could come in handy.
Say you had some old (but very useful) piece of php code you wanted to use in an ASP.net 2.0 project and either you want to cut back on time or maybe you're lazy! Or perhaps the data you're working on is on the same server or network. It wouldn't make sense using a web service in that case, now would it?
Or perhaps you are way too paranoid about sharing your data (I know a couple of people like that).
Whatever your reasons be… "PostBackUrl" is a double blessing for people like us.

Tags: ,

Programming

Comments

2/17/2010 7:21:30 PM #

Hi, I was searching the internet  and I came across your web site. Keep up the excellent work.

love calculator United States | Reply

2/22/2010 11:26:23 AM #

The 2010 Winter Olympics is halfway through and the 2012 Olympics are coming up ... Where can I find spandex worn by Olympic Athletes ?

Young Flosi United States | Reply

2/25/2010 11:51:25 PM #

Hi
I feel enjoy at your blog. Your article very helpful for me. Keep writing and happy blogging.

Thanks
Dave

Stretch Mark Removal Oman | Reply

2/27/2010 3:38:34 PM #

Hi
I found your site through search at google.  Your article very useful for me, maybe for other people too.  Big Thanks

Regards
Orie

Origins skin care Kuwait | Reply

3/1/2010 12:57:32 PM #

Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, Anyways I am here now and would just like to say thanks for a tremendous post and a all round entertaining blog (I also love the theme/design), I don’t have time to read it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the great work.

Russell Wasem United States | Reply

3/2/2010 1:40:08 PM #

Hi i am so pleased I found your blog, I really found you by mistake, while I was searching Yahoo for something else, At Any Rate I am here now and would just like to say thank you for a wonderful blog posting and a all round intriguing blog (I also love the theme/design), I do not have time to read it all at the right now but I have bookmarked it and also added your RSS feeds.

Dominic Sennott United States | Reply

3/2/2010 9:26:43 PM #

Hi thank you for an perceptive post, I actually found your blog by mistake while searching on Goole for something else nearly related, in any case before i ramble on too much i would just like to state how much I enjoyed your post, I have bookmarked your site and also taken your RSS feed, Once Again thank you very much for the blog post keep up the good work.

Justin Haaf United States | Reply

3/3/2010 2:56:48 AM #

Hello, It's a rare find for a nice blog like this. I enjoyed it. Kudos to you. Have a nice day!

Johnny flashgames Australia | Reply

3/4/2010 7:35:55 AM #

I enjoy streaming movies online, it is way cheaper than going to the theaters.

watch movies online United States | Reply

3/4/2010 7:45:28 AM #

Hey  
Nice post.
Another nice blog Google sent me to. Subscribed to the RSS feed
  will be back here soon again

Ko Phangan Hotels Germany | Reply

3/4/2010 8:55:58 AM #

Thanks for this – I really enjoyed the article and a good deal of the information here I can certainly make use of.

Regards,
Dicky

Stretch mark removal Belgium | Reply

3/5/2010 12:54:17 AM #

I love streaming movies online, it is way cheaper than going to the theaters.

free hd movies United States | Reply

3/5/2010 12:06:33 PM #

Most testers find themselves outnumbered by devs. In my case it’s about 10 to 1. (The favored ratio is a tired discussion I’d like to avoid in this post.) Rather, I would like to gripe about a problem I’ve found as I collect more projects to test. Accepting my ten devs are distributed between five projects (or app modules), each dev must attend just the Feature Review/Design meetings for the project they are responsible for. Yet, the tester must pay heed all five. Do you reckon a problem here? Let’s do the mathematics for a 40 hour work workweek. If each project’s Feature Review/Design meetings occupy eight hours per week, each dev will own 32 hours left to write code. Each tester is provided with ZERO hours to run code! The above-mentioned scenario is not that much of an magnification for my squad. The tester has no choice but to skip some of these meetings just to wedge in a little testing. The tester is required to "stay in the know" about all projects (and how those projects integrate with each other), while the dev can oftentimes focus on a single project. I conceive the foregoing problem is an oversight of many managing directors. I doubt it gets observed because the testers' time is being nickel and dimed off. Yet most testers and managers will assure you, “It’s a no-brainer! The tester should attend all design reassessments and feature walkthroughs…testing should begin as early as possible”. I concur. But it is an unreasoning expectation if you staff your team like this.

Tanesha Tippey United States | Reply

3/5/2010 5:25:04 PM #

Is tethering against the TOS of cell phone providers? Which ones allow it?

Free Mobile Service United States | Reply

3/6/2010 4:06:19 AM #

Thanks for taking this opportunity to talk about this, I feel strongly about it and I benefit from learning about this subject. If possible, as you gain data, please update this blog with new information. I have found it extremely useful.

moon in my room United States | Reply

3/7/2010 1:08:38 PM #

I am a frequent reader of your blog and just wanted to inform you that I really like your articles.

Windows Errors Hungary | Reply

3/9/2010 4:27:25 AM #

Do you know which mobile phone services allow tethering?

WoW Mobile United States | Reply

3/9/2010 11:28:24 AM #

Hello, I can’t are aware of how to include your websites in my rss reader. Will  you Allow me, please

Hypnotice Germany | Reply

3/11/2010 9:19:07 AM #

There’s some great quality information here.
Thanks for this posting, very useful for me.

Regards,
Lung

Stretch Mongolia | Reply

3/12/2010 5:40:41 AM #

I have problem with mine and here I got many info to solve my problem.
Thank you to discuss about this issues.  Waiting your next useful posting.

Regards,
Diane

Stretch Mark Removal Iceland | Reply

3/13/2010 2:19:38 PM #

Admiring the time and effort you put into your blog and detailed information you offer! I will bookmark your blog and have my children check up here often. Thumbs up!

horde leveling guide United States | Reply

3/14/2010 6:23:43 PM #

This information is awesome! I mean, like you, I’m pretty much skeptical of stretch mark creams but have read about many wonderful testimonials about different products. Which kinda got me interested in them as a stretch mark prevention tool. Will definitely check on this product range you’ve mentioned here.

Regards
D

stretch mark removal Portugal | Reply

3/16/2010 8:37:15 AM #

You should really moderate the comments here. So many spammy comments. WTF are all these people saying 'I love your post' etc. Doesn't necessarily add value to your blog... does it? But then again, going through all these comments one by one can be a pain!

reverse cell phone number lookup Sweden | Reply

3/16/2010 1:31:09 PM #

This is some useful information, no doubt.

Bob United States | Reply

3/16/2010 9:10:55 PM #

i think you have a great site here... today was my first time coming here.. i just happened to find it doing a google search. anyway, excellent post.. i'll be bookmarking this page for sure.

Jamorama Review United States | Reply

3/17/2010 3:25:58 AM #

If you're still on the fence: grab your favorite earphones, head down to a Best Buy and ask to plug them into a Zune then an iPod and see which one sounds better to you, and which interface makes you smile more. Then you'll know which is right for you.

Free PS3 Slim United Kingdom | Reply

3/17/2010 9:58:06 PM #

Great post I bookmared it on Delicious and submitted on Digg. Hopefully it sends more traffic your way Smile

stock broker United States | Reply

3/18/2010 12:30:23 AM #

Comfortably, the article is actually the freshest on this precious topic. I agree with your explanations and will eagerly look forward to your upcoming updates. Saying thanks will not just be sufficient, for the great clarity in your writing. I will directly grab your rss feed to stay privy of any updates. Admirable work and much success in your business dealings!

Tagesgeldzinsen Germany | Reply

3/18/2010 1:21:41 AM #

You made some good points there. I did a Google search about the topic and found plenty of people will go along your blog.

free flash games United States | Reply

3/18/2010 5:53:52 AM #

A quick survey of the prevailing market price of Viagra tablets will suggest that at this rate, only the elitist few will be afford a constant use of the little blue pills, an especially worrying trend.

buy viagra online without prescription United Kingdom | Reply

3/18/2010 9:57:44 AM #

Wasn't sure where to ask this but I would like to include your website in one of my directories. Please drop me a line me at your convience because I only list webistes with the webmasters consent - thank you.

Daniel Millions United States | Reply

3/18/2010 6:02:01 PM #

Thank for the post - gives us all alot to contemplate about, but despite the fact its free advice, I'm betting many will not.

Sportsbet Free Bet Code Australia | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading