ASP.NET manipulating and fire action on html - c#

I am working on a project in which one functionality is that this page obtains data from other page (not web service) and then displays it on a grid and use hightcharts for charting.
The problem is that this data I want to read is in anotherpage.
I know that I can read html from other pages... but to get this information on the page, I need to fill 2 input text for a filter and press a submit button.. then it displays a table and this is the table where I need to extract the information.
Is there a way to do this automatically on c#?

There are plenty of ways to do this; the most common revolve around AJAX. You can initiate a callback from the client via Javascript to a method on the server, which can update controls in an UpdatePanel, for example.
You can also make client side calls to server side Page Methods. Effectively, this is a static method on your webform that you can call from the client via javascript/jquery and AJAX.
EDIT.
It turns out that you want to scrape another site. The easiest way for you to do this is have a server side page method on your website that does this - it requests the page from the client site, extracts the info you want, and then returns that to your client. Your client can of course call this as a page method.
See https://web.archive.org/web/20210513000146/http://www.4guysfromrolla.com/webtech/070601-1.shtml for a tutorial, and I do suggest using the HTML Agility Pack as that article mentions.
Further EDIT
You want to further manipulate the page on the remote site; if you can't or don't want to speak to the developers of that site to work out a way of doing it programmatically, then you'll have to cheat. Get Firebug and Tamper Data. Use Firebug and Tamper Data to see how clicking the button on the remote site makes a request and posts it to the server - you want to emulate doing the same. If you know what data is being posted then you can, from your server, make exactly the same post.
You often have this kind of problem when trying to scrape AJAX websites.

Related

How to open the default browser and make it do a POST request in C#?

I think this is impossible, but I'd love to be proven wrong:
From my C# app, if the user clicks a button, I open the system's default browser with a certain URL like this:
System.Diagnostics.Process.Start("www.some-website.com");
Now, on that website there is a button that performs a POST request and updates the content of the site, without changing the URL. I would like to directly show that updated site, rather than having the user clicking around on the website manually.
Is there any way to do this programmatically in C#?
One idea is doing the POST in C# and somehow pass the response to the browser.
I know how to do HTTP requests in C# and I know what parameters I need to send here, but I don't know of a way to make the browser display the response.
Any other ideas are welcome, too.

windows form application to web page application

I have this requirement for my project. Already there is an existing windows form application,
Which sends email when a button is clicked. There's a lot of code behind the application.
It validates the field serial number which is a text box by connecting to database.
The validation error pops up as another windows form.
It generates a report form after sending an email. There's a configuration button which is accessible only to particular users which opens configuration form which has details of email settings.
Now All this is developed using windows forms. My new requirement is i need to develop
the same in a ASP.NET web page having similar functionality.
I tried using click once deployment, but that's not they needed. they want it as a webpage.
Is there any tool or way i can show the application in ASP.NET web page?
Do i need to start the coding from scratch?
Thanks in advance
As to what Rex said, you are going to have to start from scratch. The coding behind it is different. Validation and functions work differently in asp.net than they do in .net.
You will have to start from scratch for reasons already mentioned. If this is your first ASP.net application here are a few tips for what you want to do:
1- For validation and transfer to the email report to work in a similar way you can use Response.Redirect or Server.Transfer or JavaScript. All of those methods have pros and cons, see Server.Transfer Vs. Response.Redirect for an example of the first two. For javascript you'll need to write a javascript function in the .aspx file or inject javascript in the page with response.write.
2- If you validate with JavaScript you also need to validate server side to make sure someone doesn't try to pass bad values to you. JavaScript can be disabled and users can call your report page and configuration page directly, while with windows forms you control that flow you don't on webpages.
3- You'll probably have to use CSS to style elements in your email configuration form and in your initial form. Positioning, docking, anchoring and so on is completely different in webpage and done with CSS. Have fun learning the CSS boxing model, what absolute positioning is, and what clear and float do ;)
4- The most important thing is that the Web is stateless. You can't use private members to keep information between page reload on the web. When you pass a value between 2 pages the first one doesn't exist anymore so you can't just do Class.somemembervariable as usual. Check out what viewstate, sessionstate and querystring are. When your page reload, without these, everything is loss. Clicking a server-side button cause the page to reload, which you need to handle (it's called postback). This also implies that when you serve the report page you will have to pass some Id for the email and check the user, so when you call the 2nd page you need to pass to it some id so it can work. I spent more time on this one because it's the most important difference between asp.net and windows form.
5- For restricting access to your email settings page you will probably need to use windows authentification if this is an Intranet site or Forms authentification if this is an Internet site. Check Starting ASP.NET Forms Authentication for some basic overview.
6- ASP.Net has a codebehind file where you write the actual code, and an .aspx page where you put the html tags, javascript, styles, and data binding with <%= %> tags.
7- You will probably have to work with IIS as well to make your website work unless you work at a very formal place where specific peoples take care of that. At the very basic you'll have to create an application pool, make it compatible with 32/64 bits and set up authentification in IIS.

C# Basic web HttpWebRequest, does not support Javascript

I have a basic C# HttpWebRequest. My problem is the page that it is sending the GET request to, requires javascript (on the client-side) to be enabled for the content to generate.
How can I add javascript support to my code? Is it even possible?
The server can't really know whether the client supports Javascript. It can only go on the data you give it.
So there are two possibilities:
It's using headers to work out what response to send, and inferring that you can't run Javascript. Solution: work out what headers it requires, and set them explicitly.
It's sending you back the page, but you're unable to use it because you're not displaying it on a browser. Solution: look at the page, work out what AJAX calls the Javascript is making, and make those instead. You may not even need to fetch the original hosting page.
HttpWebRequest just implements GET, you need full browser to execute JavaScript (and possibly need CSS files to as scripts may depend on them).
The built in approach is to use WebBrowser control to render pages, that grab innerHTML after you find that JavaScript rendering is done.

Refresh client browser when adding new line in a specific table

My scenario:
After client login, my user will be redirected to the index.aspx page.
Inside this page I will put one div with a gridview inside.
This gridview will be showing data from one table.
My question is: How to refresh this gridview always that one record is
saved on this table?
Ps.: I´ve seen a lot of examples using "server push" tecnology, comet, ajax, etc.
Don´t know the best way to do that and can´t find a really simple example.
When a new record is added to the table, the real challenge is communicating those changes to the client in real-time without polling in intervals or requiring some sort of user interaction.
You have a couple of options:
Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.
Here are some examples using WebSockets:
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
HTML5 C# WebSockets Server and ASP.NET Client Implementation
C# WebSocket Server
WebSockets in ASP.NET 4.5
WebHooks and WebSockets in ASP.NET
There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.
Here are some tutorials to check out:
WebSync Tutorials
PokeIn Basic Tutorial / PokeIn Advanced Tutorial
Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.
You can use setinterval javascript method. I act as a timer and use submit form to refresh the page. other method could be asp.net ajax toolkit timer control here
put your grid inside an update panel and set "Update Mode" to always
You can use Update Panel which uses AJAX under the hood. Refer to this link for a short and simple demo.
You can also use plain old html
<META HTTP-EQUIV="REFRESH"
CONTENT="15;URL=http://www.I18nGuy.com/index.html">

recommended way to handle this case in .NET for web application

I am relatively new to web development and am trying to figure out what would be the recommended way to deal with my current situation.
All of this needs to be in the .NET framework.This is a very simple use case, but I am required to deal with a bigger problem here.
Here is the flow of things:
Client clicks a button on a page: "Calculate Sum"
This invokes a call to the webservice which calculates the sum and returns some extra info on how to render it on the html page
The client receives this info from the webservice and populates one of the variables in the javascript that is used in the resulting page and the extra info is used to render the html page
The resulting page would have a button; when clicked would redirect to a third party application. It would then process this request and send a POST back to one the URLs I have specified. I am then required to consume the info (string) that they would send back.
Let me know if I am not clear in any of this and if you want me to specify more info. This is more about learning on the job and so I am trying to find out the best way to solve this problem.
Thanks
It sounds like, if as you say everything must be in .NET framework, then you can use Visual Studios to develop this project in VB or C#. Essentially, the page that initially sends the request to the web service would be built as a .aspx webpage. Then you can build a web service in C# or VB .asmx which handles the calculation, returns a result that is parsed by javascript on another asp.net web page and produces a button to send the gathered data as a POST to another URL.

Categories

Resources