im presently using two buttons in a form and a webbrowser control.
button1-Navigate to the page
button2-Fills user,pass and then submit
like this

private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://www.xxxx.login.aspx");
        }
private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.Document.GetElementById("username").InnerText = "aaaaa";
            webBrowser1.Document.GetElementById("password").InnerText = "bbbbb";
            webBrowser1.Document.GetElementById("login").InvokeMember("click");

and it works fine. but now im in a need to do this in a single button click, when i put those two codes under single button click event im getting exceptions.

how ca i do this in a single button click with webbrowser control.

Recommended Answers

All 3 Replies

If I understand correctly, rather than having the user press a button to bring up the page in the WebBrowser control, you could put "webbrowser1.navigate" statement into the "Form_Load" method of the form. Just double-click in a blank area of the form and the code window will appear, with the cursor in the "Form_Load" method.

This way, when the form loads and control is given to the user, the WebBrowser control will already be populated with the page you want.

If I understand correctly, rather than having the user press a button to bring up the page in the WebBrowser control, you could put "webbrowser1.navigate" statement into the "Form_Load" method of the form. Just double-click in a blank area of the form and the code window will appear, with the cursor in the "Form_Load" method.

This way, when the form loads and control is given to the user, the WebBrowser control will already be populated with the page you want.

thanks for ur reply..

u r right.. but my prob is i need to login with one user id, password with button1 click and i need to login with another user id, password with button2 click.. so when i put that navigate method in form load event it works fine for button1 click. after it works if i need to login with another it shows exception since th webbrowser control does not currently have the login page. So i need to have the navigation and login to be done with a single button click. Hope i am clear now.

now help me..

I'm not completely sure I follow you... Are you saying:

1) You need to login to a page with the first username/password, wait until the page loads, then (somehow) login again using the second (different) username/password,

or

2) You need to use 2 webbrowser controls, one for the first set of credentials, and another for the second set.

I guess I'm trying to figure out why you need to login twice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.