Using a variable in the web browser control - c#

I am developing a windows phone 7.1 application, which will search through different search engine after taking in the text from the textbox. I have textbox(searchBox), four buttons for bing, google, facebook and yahoo and a web browser control. Now i need to pass the text from the textbox to the web browser. But the thing is it should be of the form "www.bing.com?q= textbox.text". how can i implement this?

You can adjust WebBrowser.Url property
Link : http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.url.aspx
Or you can use Navigate method
var address = "www.bing.com?q=" + textbox.Text;
webBrowser1.Navigate(new Uri(address));
Link : http://msdn.microsoft.com/en-us/library/ms161352.aspx

Related

Update label + 1 Per Web browser Refresh at a specific time using c#

my question is how can i update label + 1 per web browser refresh at a specific time using c#,
I want to be able to set my timer through textbox..
I want the web browser to refresh after the the time i set through my textbox in the timer has exceed..
And once the web browser is refresh, i want it to a + 1 to my label (example i set my label to 0 so once a url is refresh it should change to 1, one refresh two time the label should be 2 and so on)...
I want to be able to stop the timer...
please how can i achieve these in c#....Thanks very much
Note : It is a Window form Application...Thanks
What you are asking is unfortunately impossible, since you want to manipulate a different application from your application.
What you could do is implement a WebBrowser control in your forms application, which renders a browser in your application.
This browser can be manipulated by you. Refresh by using webBrowser1.Refresh();. (Where webBrowser1 is the name of your webbrowser control.)
See the following documentation on webbrowser controls:
Webbrowser controls

how to Pass value from windows application form c# to html page

I made an project for access google map from windows application with in that just I created one form with button and textbox name called txtsource and txtdestination , when the user perform click option on button the bellow code will execute
string startupv = (Application.StartupPath + "\\Default.htm".ToString());
System.Diagnostics.Process.Start(startupv);
and call Default.html page
in default.html page having two textbox for get the user source and destination value .What I actually expecting here mean from the windows application txtsource and txtdestination textbox value should pass default.html page textbox.
With out using Webbrowser.
If you are just looking for a solution where you pass some values to a web site and show the response on windows application then you can try.
HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://somewebsite.com/Default.html?source=SomeValue&Destination=SomeValue");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
if you want to open a web browser then passing the values by query string as GET parameters might work.
string startupv = ("http:\\somewebsite.extension\" +
"\Default.html?source=SomeValue&Destination=SomeValue".ToString());
Get these values from the link in the web application.

WebView Windows 8.1 TextField

I am using Webview to displays an html page that contains 2 inputs of type text and a submit button.I want the app user to be able to fill these fields on the app before launching the webview.Therefore taking the user directly to the result of the search.
Apparently the webview.Document is no longer available.
Any suggestion ?
Once the HTML is loaded into WebView, you can call a method called InvokeScriptAsync through which you can invoke some kind of Javascript.
await myWebView.InvokeScriptAsync("eval", new string[] { "var elem = document.forms[0].submit();"});
This way you can fill the input field, click a button or whatever you need.

Use text box in another page to edit code of a button?

I'm creating a web browser. On the "mainpage" it has a button that takes you to the homepage, i'd like to give the user the option of changing the home page on "page1" (settings). on page1 I have "textBox1"(where the user enter desired homepage) and "button1" (set). Could you help me set this up? Is there a way where doing that action can change the source of webBrowser1?
First I would suggest you to download this Programming Windows Phone 7 ebook and explore it to learn Windows phone programming before asking StackOverflow.
Coming to your question,
Create a Settings class in the project and Add a static string property named something like "HomePageUri". Then in your Page1, add the source uri to that "HomePageUri".
Then in your main page, in the OnNavigatedTo event update the WebBrowser's source or you can bind the WebBrowser's source directly to the "HomePageUri" property
Good luck

Filling a HTML form with C#

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");

Categories