tags:

views:

817

answers:

5

I need to request a page (I'm using httpwebrequest at the moment), call some javascript ( e.g

function selected(id) { document.getElementById("selected").value = id; }

and then submit that back to the server . . . is this possible?

EDIT

Sorry for the vagueness.

The page I'm trying to interface with is already 100% working, all I need to do is find a way to trick the server into thinking that someone has loaded up the page, caused a piece of jScript to be run, and submit it back to the server, like a faux user. I'm trying to use the embedded webBrowser on a winForm at the moment, it's easiest to do it this way because the code that waits to be told when to make this request is already written, it just needs to be able to simulate the squishy human that's not in the middle.

Incase you can't tell I'm currently learning javascript so forgive me if I'm not too sure with something basic ^_^

A: 

The only way I know of would be to implement AJAX into your wepage. We really need to know more about it in order to see how to do it, but it shouldn't be that difficult.

Matthew Doyle
A: 

Are you submitting a form? Get, Post?

If you are, just give the server back the form data it's expecting. No need to manipulate the UI.

Diodeus
A: 

This is hard. Since you get the result as html text, let's say somehow you find the js code that you want to execute in that html page, there is no mechanism that can interpret your js code.

Maybe you should consider using ie browser component in your app.

But if you just want to send back a particular data, thats easy; just set post & get variables while you are requesting the page.

erdogany
A: 

The Prototype JavaScript library has an evalScripts option that allows JavaScript in the response to be executed. It has limitations, but it may help.

Jack M.
+2  A: 

If you're using HttpWebRequest to pull a "page" (or other resource) from the web into your C# app, you're essentially going to be working with the page as a string. You don't really have a context in which to execute JavaScript...there's no DOM or JavaScript engine unless you have a browser to give you those things. For a simpler solution, I'd ask if there's a way to get the same functionality you're looking for by working directly with this page as plain text in C#? In you're example (and I'm guessing this is a very simplified example of what you're looking to do), you're looking to get the value of a DOM element. You can use string or Regex functions to get that kind of information. If all you're looking to do is pull textual information from the resource you're downloading, that might be a simpler solution.

Rich