I have created a web browser in c#
this was what i get when i opened my web browser and typed google. Then i searched google for something
the result was like this
But the url wasn't updated in address bar. How to update the address bar when user click on a link on any website in my web browser
In the first image the url was google.com
In the second image url was https://www.google.co.in/#hl=en&output=search&sclient=psy-ab like that some thing but it wasn't updated
You must update the textbox on top with the URL of the WebBrowserControl, using the webBrowser1_Navigating event.
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
textbox1.text = webBrowser1.Url.ToString();
}
Check http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser_events.
I think you can use Navigating event to detect when user starts search or navigates to another page.
The Form_Load must contain this:
private void Form1_Load(object sender, EventArgs e)
{
web = new WebBrowser();
web.Navigated += web_Navigated;
}
and this function:
private void web_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
textBox1.Text = web.Url.ToString();
}
Related
I have an asp.net page and I am trying to open a new one asp.net page on a button click in a new window as a popup and not in current or in a new tab.The method which the button click calls is :
private void OpenNewTranslationPage(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(),"OpenWindow","window.open('CreateProject.aspx','_newtab');",true);
}
I think that the _newtab is not proper, but I am wondering how it can it work.
Use the _blank property like
window.open('NLGCreateTranslationProject.aspx','_blank');
See https://developer.mozilla.org/en-US/docs/Web/API/Window/open
To open a new window on every call of window.open(), use the special
value _blank for strWindowName.
You can try the below code:
protected void imgbtnPrint_Click(object sender, ImageClickEventArgs e)
{
Response.Write("<script>");
Response.Write("window.open('ApprovalsByAccountPrint.aspx','_blank')");
Response.Write("</script>");
}
I am trying to automate fill the textbox of a website in c# and i used:
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.WebBrowser webBrowser = new WebBrowser();
HtmlDocument document = null;
document=webBrowser.Document;
System.Diagnostics.Process.Start("http://www.google.co.in");
document.GetElementById("lst-ib").SetAttribute("value", "ss");
}
The webpage is opening but the text box is not filled with the specified value. I have also tried innertext instead of setAttribute. I am using windows forms.
You are expecting that your webBrowser will load the page at specified address, but actually your code will start default browser (pointing at "http://www.google.co.in"), while webBrowser.Document will remain null.
try to replace the Process.Start with
webBrowser.Navigate(yourUrl);
Eliminate the Process.Start() statement (as suggested by Gian Paolo) because it starts a WebBrowser as an external process.
The problem with your code is that you want to manipulate the value of your element too fast. Wait for the website to be loaded completely:
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
webBrowser.Navigate("http://www.google.co.in");
}
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser.document.GetElementById("lst-ib").SetAttribute("value", "ss");
}
Please note that using a instance of a WebBrowser is not often the best solution for a problem. It uses a lot of RAM and has some overhead you could avoid.
I want to read text from TextBox and then send it to another page. But on another page I keep geting empty string.
why this doesn't work ?
I have this on page 1:
public string _beseda()
{
return textBox1.Text;
}
and on page 2 where I should retrieve this string:
private void button1_Click(object sender, RoutedEventArgs e)
{
Page2 neki = new Page2();
MessageBox.Show(neki._beseda());
}
There are two strategies to pass data between pages in windows phone.
Use App.cs
Pass data as parameter values during navigation
1. Using App.cs
Open up App.cs code behind of App.xaml write:
// To store Textbox the value
public string storeValue;
In Page1
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
App app = Application.Current as App;
app.storeValue = textBox1.Text;
}
on Page2
private void button1_Click(object sender, RoutedEventArgs e) {
App app = Application.Current as App;
MessageBox.Show(app.storeValue);
}
2. Passing values as parameters while navigating
Before navigating embed textbox value to the Page Url
string newUrl = "/Page2.xaml?text="+textBox1.Text;
NavigationService.Navigate(new Uri(newUrl, UriKind.Relative));
in Page2
//Temporarily hold the value got from the navigation
string textBoxValue = "";
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//Retrieve the value passed during page navigation
NavigationContext.QueryString.TryGetValue("text", out textBoxValue)
}
private void button1_Click(object sender, RoutedEventArgs e) {
MessageBox.Show(textBoxValue);
}
Here are a number of useful links..
How to pass the image value in one xaml page to another xaml page in
windows phone 7?
How to perform page navigation on Windows
Phone
There's a number of issues. You say you have that _beseda() function on Page1, but you reference Page2() in button1_click(). Additionally, if I assume you meant Page1 in button1_click(), you're creating newPage1 and then you ask it for the text box's text.... so of course it's empty. You haven't put anything in it.
Even if you meant to put Page2 there instead, the problem is still the same.
I created a winForm application which fills the fields of a web site :
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(new Uri("http://www.site.com”));
this.textBox1.Text = this.webBrowser1.Version.ToString();
}
private void button1_Click (object sender, EventArgs e)
{
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
document.GetElementById("login").SetAttribute("Value","user");
}
It works perfectly when the web site page is loaded in application control but when I want to open it in a new browser using webBrowser1.Navigate(new Uri("http://www.site.com”),true); the page fields are undetectable.
Is there a solution for this problem? Thanks in advance
I have a panorama app and made a button on one of the pages. How can open up a page when the user clicks the button?
private void button1_Click(object sender, RoutedEventArgs e)
{
SearchPage sp = new SearchPage();
sp.Visibility = System.Windows.Visibility.Visible;
Now, the sp.Visibility seems to be the wrong way to go about it. Could anyone help me figuring out how I show secondary pages?
Just like web applications, in your silverlight application you need to redirect the user to the next page.
NavigationService.Navigate(new Uri("/SearchPage.xaml", UriKind.Relative);
you can pass parameters to your page by adding query string parameters:
NavigationService.Navigate(new Uri("/SearchPage.xaml?name=" + txtName.Text, UriKind.Relative);
and in SearchPage.cs you can retrieve the query string by saying this:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
var name = NavigationContext.QueryString["name"];
}
When you say a page, you mean a panoramaitem or a new page in your application?