I have a php website which i want to run in C# wpf webbrowser control.

I have a validated a username and password for the site by connecting to it's database using .net.

Now i want the functionality to take username and password and submit the post form to php page that will validate the username and password again(of course it is already validated) or not validate and send the user to the page that it needs to redirect. and i want that page to be seen in my webbrowser control.

How do i do this.

Recommended Answers

All 4 Replies

Have you tried modifying the DOM to include JavaScript for form submitting, and then doing it like that? You can invisible DIV over the entire page and onmouserover it if you can't do it from the control itself. If you have access to the DOM through the web browser control in WPF the sky's the limit. Oh, and to answer that question for you:

http://rhizohm.net/irhetoric/blog/72/default.aspx

You have control.

I have a php website which i want to run in C# wpf webbrowser control.

I have a validated a username and password for the site by connecting to it's database using .net.

Now i want the functionality to take username and password and submit the post form to php page that will validate the username and password again(of course it is already validated) or not validate and send the user to the page that it needs to redirect. and i want that page to be seen in my webbrowser control.

How do i do this.

I found the solution.

Thank you

Could you share with us?

There is myWebBrowser.NavigateToString method in which we can pass the string that consist of a web form and a javascript function which submits the form when it loads, for example the code is given below:

string documentText = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
                        "<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
                        "<head>" +
                        "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" +
                        "<title>Untitled Document</title>" +
                        "<script type=\"text/javascript\">" +
                        "function SubmitForm()" +
                        "{" +
                        "    document.forms[0].submit();" +
                        "}" +
                        "</script>" +
                        "</head>" +
                        "<body onload=\"SubmitForm()\">" +
                        "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"http://www.mywebsite.com/index.php\">" +
                        "<h1>Loading....</h1>" +
                        "<input type=\"hidden\" id=\"txtUsername\" name=\"txtUsername\" value=\"" + txtUserName.Text + "\" />" +
                        "<input type=\"hidden\" id=\"txtPassword\" name=\"txtPassword\" value=\"" + txtPassword.Password + "\" />" +
                        "<input type=\"hidden\" value=\"Sign In\" />" +
                        "</form>" +
                        "</body>" +
                        "</html>";
                        myWebBrowser.NavigateToString(documentText);
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.