Auto fill web page using ASP.Net C# web page - c#

I need to write a ASP.Net C# web page that can open a web page, fill in the fields and click the submit button on the web page automatically. My web page should launch the IE browser and navigate to a specified URL and fill the form and submit it. Not sure where I should start from. Any help is greatly appreciated.
Thank you.

I'm not sure that, browser will allow to run all your js code.
But you can try with jquery, or with some another javascript lib.
You can add to your page iframe tag, than add dynamically another web-site to the iframe content. You also must know id's or classNames of html controls.
if you're going to use jquery
$(document).ready(function () {
$('#textbox1').val()="someText1";
....
$('#textboxN').val()="someTextN";
//call click event
$('#btnID').click();
});
to automatically start your page, you can use Process.Start() method in server side.
if you're trying too run in client side, you can use Response.Redirect Method

Why not make a POST/GET call directly?
You could use HTTPWebRequest
http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

Related

How to download infinitely-scrolling web page

With WebClient.DownloadString method it's fairly simple to load normal web page source to string.
But is there any easy way to load those pages which extends and loads new content when you scroll down to end?
You cannot "download" such a page, as it doesn't exist in full form. Such pages require user interaction.
You can use one of the forms of the WebBrowser control to browse to, and programmatically interact with a web site.
hey you can try this approach if you want to do it webclient..
See here.. basically he is using the scrapy but this approach can be adopted in case of webclient to i think so.
basically he is using the firebug or chrome developer tool in order to trace the ajax web request after knowing the web request you can get the content with webclient.

web site scraping data

I am working on web site scraping project where I am using webbrowser control in C#.net
I almost done these by going from page to page and collecting data.This project has to run automatically.
One page has JavaScript function and there is alert message notification is popping up. How I can pass this alert?Is there any way to comment it out or call click method?
Please help with this.
Thank you in advance

Call a C# function from a button clicked on an HTML page

My application (C#) consists of an embedded web browser which will load a page in HTML from a server. The HTML page will be created from scratch for this particular application. My intention is to have the following procedure:
A user opens the application
A web browser embedded within the application will load an HTML page
User will click a button on the HTML page
A C# function (on client side) is triggered from this action
function does some work
send a list of data back to the web page
Web page will retrieve this data and display it
user's browser will be refreshed to display the new page
Now my questions are the following:
How can a C# function on the client side be triggered when a button is clicked on a server page
What is the best way to transfer data (will probably be object)
how can a function on the HTML page wait for data to be received before continuing to execute the function?
Using the WebBrowser control, you can use the ObjectForScripting property. This will allow JavaScript to call C# code using window.external.C# MethodName
There's some quirks with the serialization you might need to work through, and you might need to use webbrowser.Document.InvokeScript to trigger your data back to JavaScript (I've not personally used the result of a window.external call so cannot speak for it).

.net webhandler force download dialog to client c#

I am having a bit of a problem with a web applcation I am developing in .net with C#. I am using a WebHandler that responds to an ajax call from the client, and executes a function that creates a file. What I want is to display download dialog at the end of the file creation process, however the Response class does not exist in the context of the function called by the handler. How to force the application to show the download dialog to the user after file creation? I was thinking about uilding a callback function to the ajax call, and when the execution of the first ajax call returns do another ajax call to a different WebHandler that will force the download dialog. Is this the most efficient way to do this? Is this even correct? What other more orthodox ways can I use to achive what I want? Thank you for yor help.
Consider taking AJAX about of the solution and just redirecting or setting the window.location to the WebHandler url, which will trigger the file download dialog on the browser. Once the user accepts the download, the browser will remain on the page.
Maybe there are more details as to why Ajax is needed. If so, please add them to the question.
On the success operation of your ajax call once the file has been created by the handler just navigate to the file... eihter using C# or JavaScript

filling web form using a windows application in C#

I have a site which get information of user in one of its pages.
every user has a card which contain his information. I want to write a windows application in Visual C# which read the card and fill web form using those data.
for this reason I have to run a browser in my windows application and run some javascript code to fill that elements in that browser.
does any one how can I run a browser and give to that specific javascript (in url after on page has been loaded) to fill the form?
There is a WebBrowser control that you can use in your windows app. As for populating the information on a web page, I would just pass the userID in QueryString to the URL of the page you create (in your WebBrowser control), and in the page add code to retrieve the user information and display it.
Here is some info on the WebBrowser control:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx
My guess is you would be better off handing over the data you want to see in the web forms via http post or get. Then let the serverside write the values into the propper forms.

Categories