external POST request to update on aspx page - asp.net

I am working in .net webforms and am submitting something to an external web service via .ashx which then returns a POST request with parameters to my .aspx page. I am having trouble figuring out how to get that data back on my page.
I understand that Request.QueryString["parameterName"] should get anything sent as a querystring, but how can I then take that information and, say, put it in a label on the page in my browser.
Basically I want this: user is on .aspx page, clicks a button, processing happens externally and information from the POST request from the webservice is then displayed on the screen for the user on the same .aspx page.
I assume this involves and needs some ajax - I just am not quite comfortable enough with it to know how to do it and if what I am doing is right.
Any help would be much appreciated!
thank you in advance,
syd

Related

Do webforms post to server on every page change?

This might be a very basic question that I should already know the answer to but I can not seem to validate it.
I would like to know, in a webforms app (DotnetNuke) there is a master form which is created by DotNetNuke
<form method="post" action="/buynow?mode=form" onsubmit="javascript:return WebForm_OnSubmit();" id="Form" enctype="multipart/form-data">
In the app I have some fields and a button which fires a jQuery ajax POST to an external API. On the success of the post I use jQuery to redirect to a new page.
On this redirect will the form be posted to the server? I ask because in order to be PCI compliant I can not have the content of this form post to my server.
If it does post the form data by default is there a way to prevent it, or would it be just a matter of clearing the form fields before the redirect will solve my issue.
I use jQuery to redirect to a new page
Assuming you are using window.location to set the new URL, this will perform a GET of the new URL. No POST to the original URL (or anywhere else) will occur.
Many ASP.Net server controls cause a POST back to the same page, but these POSTs are almost always in response to a user action (a click, a dropdown change, etc.).
In general, you don't have to worry about postbacks occurring without your knowledge, but when in doubt, fire up a network sniffer (Firebug, Chrome tools, IE tools, etc.) to be sure.
I use jQuery to redirect to a new page
When you use redirect you are instructing the browser to perform a GET. In other words the browser won't perform a POST.

Legitamate cross site communication

I am building a website, within a large intranet, that wraps and adds functionality to another site within the same intranet. I do not have access to the other site's source and they do not provide any api's for the functionality they provide. I need to, somehow, have my server-side code go to that site, fill in some forms, then press a submit button.
Is this possible? If so, how can I accomplish this?
Note: I am working in asp.NET if that matters at all.
Not the most efficient, but maybe WatiN can get you started:
http://watin.sourceforge.net/
Just look at the URL the form is supposed to submit to and the method it employs (POST or GET) and then send a request to that URL using the same method and put the field you want as parameters
Your server-side code is basically a web client to the other web site. You will need to write the code to send the HTML form data to the other web site and process the response. I would start with the System.Net.WebClient class. Take a look at System.Net.WebClient.UploadValues. That class/method will enable you to POST the form data to the web site via a NameValueCollection.

File Uploading without page refresh in Web pages

Hii,
Any one knows how to upload files to the physical location of the server. It is possible using file upload control that i know. But i want to avoid the external postbacking of the page. For e.g exactly like what in the yahoo mail did.
In yahoo mail latest version if you attach a file that won't post back and attach that file in to server. What is the technology behind that?
Normally when you submit a form it does a POST request to the server, causing a refresh. Ajax requests get round this by using JavaScript to send the POST data through to the server, and that doesn't need a page refresh.
Ajax requests can't be used to send file data though, so the best way to currently do it is with an iframe hack - you use JavaScript to dynamically build up a form within an iframe, submit that form via JavaScript, and listen for the iframe's onload event. So you know when the form has been submitted. A version of this approach is detailed here:
http://www.webtoolkit.info/ajax-file-upload.html
Other methods to do this would include using a Flash-based solution like http://www.swfupload.org/ or a wrapper like http://www.plupload.com/ - these will prevent you having to roll your own solution and will also provide some extra functionality - upload progress feedback, for example.

ASP.NET - Send Information to Website

I have an asp.net webpage that only contains a textbox and a button. The user submits their email address using this webpage.
What I am trying to do now is take the information submitted by the user and go to another website. Where my "website/program" gives the different website the entered email address, and clicks the submit button.
If I where to physically go to the different website, there would be a textbox to enter the email. But since I am accessing the website from my page "behind the scenes" I cant manually enter their email address...
Is it possible to do this, if so how? Also, my code behind is in VB.
Thanks!
Well it can be done, but the simpllicity of it depends on what this other webpage is. Will this webpage always be the same or can it change?
If it a dynamic website that will frequently change, then you will need to basically parse the html and emulate how the email address gets posted to the webpage. Look for the tag in the html and see what page it posts to.
What you want to do is use HttpWebRequest. This class can send information to another web page. Here is a tutorial on how to do what you are asking: http://www.jigar.net/howdoi/viewhtmlcontent106.aspx
And here is the MSDN documentation on it: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.71).aspx
Keep in mind that my solution will work if the web site is using POST or GET, but some sites use Javascript. To do this, it will require you to build a javascript interpreter.

Dynamically loading content (ajax) other than using page methods

I'm working on a site at the moment that loads all of its browser popups by using page methods. This approach works but it's starting to get messy. I also view page methods as ways to perform small tasks, username availability comes to mind.
What other options are there besides page methods and the update panel?
You should look at the JQuery ajax functionality. http://api.jquery.com/category/ajax/
You can point the url of the AJAX request to an aspx page or an html page or pretty much any web resource that you like, as long as the request is handled on the server by some kind of HttpHandler. And as long as your callback handler is able to handle and display the returned resource
PageMethods sounding fine to me (which are essentially Webservices).
You could pull more data per request and use cache more. You could build a better JavaScript wrapper which satisfies the need for more tidiness.
You could choose another library: How to call a web service from jQuery

Resources