I need help with connecting to a certain website via my username & password.
With WebClient I can fill the username field and the password field, but how do I invoke the click method of the button?
And How can I fill a specific textBox that doesn't have an ID?
I tried doing this with webBrowser, but every time I navigate I have to use a new function every time, which makes the work much harder.
Thanks.
What you're trying to do is wrong. If you want to Post some data to a web address (a URL), simply create a web form (a simple HTML form), fill it, and then send it. Just consider these notes:
Your HTML's form action should be the exact URL of the form you're imitating.
Your input controls should have the same name attribute value.
For more information, see Form Spoofing
Look at the web browser control and see if you can use that inside your windows form to perform the task that you are doing. Once you are satisfied with the results, you can make the web browser control invisible, and it'll work just like you do with web response and request calls.
View the source code and find the id of the button (say "Login").
Then use:
HtmlElement elem = webBrowser1.Document.GetElementById("Login");
if (elem != null)
elem.InvokeMember("click");
Related
i have create a user control search.ascx with query string values and i m accessing this page from Parent page(Rcomm.aspx) and now this Page is open from another page(view.apsx) on button click using hyperlink navigateurl. my question is that how can i pass my user control query string from view.aspx
A user control has access to the page's URL the same as any normal ASP.NET page does; thus, in order to retrieve the QueryString from the user control, the normal syntax will work:
Request.QueryString('key')
However, I consider this poor style, because I think of user controls as a modular item you can embed in ANY page: thus tying it directly to a particular querystring value seems to go against that. However you may have valid reasons for this.
I'm not sure I understand the second part of your question:
how i make hyperlink navigate URL with query string for open my Rcomm.aspx
Could you please clarify?
ADDITIONAL: OK it seems to me like you have a link in your user control, and want to use a querystring value from the user control's parent page (Rcomm.aspx) to use in the link to a third page. Correct me if I am wrong.
In this case, you would read the querystring from the user control, then append to another URL using NavigateURL:
URL: Rcomm.aspx?field=value
(in code behind:)
Dim qs as string
qs = Request.QueryString('field')
MyHyperlink.NavigateURL = "newpage.aspx?field2=" & qs
Or something similar. Yes?
What's the best way to do synchronous navigation to a string with the WPF web browser control?
I know the WebBrowser.NavigateToString(string) does display a string, but it's done asynchronously—not synchronously. On top of that, WebBrowser.NavigateToString always returns a body of null in the WebBrowser.Document area while WebBrowser.Navigate actually returns a body in the document.
In WinForms I could do: WebBrowser.Document.Write(html); but in WPF I can't figure out a good way to do this. I have a function that navigates to a string and returns a value so I do not want to use the WebBrowser.Navigated event...
You need to retrieve the body first using HttpWebRequest, then process it however you want, before displaying it in the WebBrowser
I have an aspx web page (opener) which opens a popup window
In the popup window I need to retrieve the value of a hidden field which exists in the opener page.
So this is all straight forward using Javascript.
However, here’s the problem, I need the value of the hidden field to be processed SERVER side before the pop up page loads
(Basically, the hidden field contains XML which need to be deserialized server side and the data used to construct the DOM of the popup page)
So how do I pass the data in the hidden field of the opener, to get processed serverside in popup?
The data is Waaay too long to be passed as a GET. i.e. in the querystring of the popup page
What are the other options here?
Retrieve it using Javascript in popup, then do a postback to reload the page (very ugly)
Somehow post the data when opening the popup? Is this possible and can I stil pass other info via the querystring
Any other ideas?
Have a form like this
<form method="POST" action="action.php" onsubmit="open_popup(this);">
<input name="really-big-field" type="hidden">
</form>
also, javascript like this
function open_popup(form)
{
window.open('action.php', 'actionpopup','width=400,height=300');
form.target = 'actionpopup';
}
window.open() will open a popup like you want.
Setting the form's target to the opened popup will make sure that the form will POST to that popup.
Since a POST is made, you can send larger data than you can send using GET.
You can process the data server side in action.php (or in ASP.Net/VB file).
My usual solution to this sort of issue is to use XmlHTTPRequest to post the XML to the server, which simply stores the XML against some unique ID such as a GUID and have the ID returned from the server.
The URL you provide for your popup would then only need to carry this ID rather than the whole XML. Now when the server code on the other end of that URL needs the XML it can use the ID to look up the XML (probably deleting it from its temporary store at the same time) and can process the XML as if had been posted in the request.
Edit: Sorry, I realize this doesn't answer your question. I didn't read it clearly enough and didn't realize you needed to do it server side. I suppose if you wanted to take this path, though, you could then AJAX up your page to build it.
Parent page:
foo = 'bar';
child = open ("popup.html");
// you can now access the new windows functions with child.varname and child.function()
Child page:
alert(window.opener.foo);
Should alert Foo. Therefore you can:
somevar = window.opener.document.getElementById('id').value;
to get the field's value.
I have a javascript code which builds a link with 2 params.
Now, I know how to post these params using the address, but I don't want to use it.
I've tried using cookies for posting the params, but somehow I can't read them on the server side.
this is the client side code
document.cookie="name="+"value";
this is the server side reading code
string s = Response.Cookies[cookieName].Value;
Can you hep me out?
Create a mini form (not an asp.NET web form, just a simple one) with two input type hidden fields named as your parameters. After that create a link or button an tie the onclick event of it to a javascript function (example: onclick="javascript:postIt();").
Then when user clicks the button or the link the function will replace the value of those parameter something like:
document.miniform.parameter1.value = yourvalue1;
document.miniform.parameter1.value = yourvalue2;
document.miniform.submit();
To get the parameters back into code use Request.form("parameter1") and so on...
You can use an Ajax Request to post your data to an ASP.NET form.
To post data to any page, you HAVE TO use the path to that page. As for your problem with setting the cookies, they can only be used by a page in the same domain.
Are you doing an HTTP Post? You could post these values inside a form field. I'd use a hidden input field. You can add one in your markup or add one via the javascript.
Your other option is to use some sort of Ajax and pass JSON or XML in the body of the post.
Cookies are meant to save data client side accross pages and/or sessions.
I am designing a winforms based testing app (which is based upon WatiN). I specify a page to test and the value to insert into a textbox, and then click the corresponding button.
Is it possible to add a query string to the request I make (when clicking button) and then get the URL of the next page? Based on this, I need to screen scrape it.
Not sure about Watin syntax, but in Watir (Ruby version) you can get URL of the page displayed in browser with
browser.url
Or do you need to get URL of the next page before you open it?
Based on your comment to AmitK, Željko's answer is right.
In WatiN (and C#), the syntax is:
Console.WriteLine("The current page is:" + ie.Url.ToString());
(just in case: 'ie' is the browser reference, use whatever object you use to enter text and click buttons)
What exactly do you mean by "next page" ? Does the form when submitted redirect to another page? If so, you will receive a HTTP 302/303 status code with the URL of the next page.