2013-08-21 28 views
0

我正在用c#編寫一個程序。在最後的形式中,我得到了一個名爲「電話簿」的按鈕。當我按下它時,它應該打開一個帶有「tel.search.ch」網址的網頁瀏覽器(它是瑞士的德國網站)。我已經研究過網站的網址。它是這樣的:使用c在電話簿網頁上的webbrowser動態鏈接#

tel.search.ch/?what=forename+surname &其中= livingplace

但是當我按一下按鈕,它會打開網頁瀏覽器,但該網址是該網站的主站點。所以webbrowser導航到tel.search.ch而不是我定義的URL。在這裏你可以看到我的代碼:

Form5(最後形式按鈕):

private void btnTel_Click(object sender, EventArgs e) 
     { 
      Form6 form6 = new Form6(); 
      this.Hide(); 
      form6.Show(); 
     } 

Form6(網頁瀏覽器):

public partial class Form6 : Telerik.WinControls.UI.RadForm 
    { 

     public Form6() 
     { 
      InitializeComponent(); 
     } 

     public string forename; 
     public string surname; 
     public string address; 
     public string postalcode; 
     public string livingplace; 


     private void Form6_Load(object sender, EventArgs e) 
     { 
      webBrowser1.Url = new Uri("http://tel.search.ch/?what=" + forename + "+" + surname + "&where=" + livingplace); 


//this code is that my program got the value of the textbox from form1 and form2. it is defined in Program.cs 
       Program.forenametext = vorname; 
       Program.surnametext = nachname; 
       Program.livingplacetext = ort; 
      } 
     } 

我不知道爲什麼在網頁瀏覽器導航到家庭本網站的網站。有人有個想法嗎?

歡呼

+0

你確定你的URL格式是否正確?我嘗試了你給的那個,它似乎沒有工作。但是玩弄網站的按鈕,發現像「http://tel.search.ch/?was=john」這樣的東西確實有效。 –

+0

hm是的我已經在ie,ff和chrome中測試了很多次,它似乎工作。只有當我運行它的程序,它不起作用 – Roman

回答

0
webBrowser1.Url = new Uri("http://tel.search.ch/?what=" + forename + "+" + surname + "&where=" + livingplace); 

你的變量forenamesurnamelivingplace不被初始化。網址看起來像http://tel.search.ch/?what=+&where=。所以你的URL(特別是查詢字符串)沒有被網站解析,而是被重定向到主頁。你可以通過加入一些靜態值或初始化來檢查它。

即使您使用的是錯誤的網址,並且對forename + "+" + surname也不使用+。這將是:

webBrowser1.Url = new Uri("http://tel.search.ch/?was="+forename + " " + surname+ "&wo=" + livingplace); 
+0

這可能是,但我猜所有的代碼沒有被顯示。 –

+0

噢,就是這樣!我寫下了一些隨機文本,而不是名字,網站開始正確。我會看看它。謝謝你的傢伙! :) – Roman

+0

是的,它現在的作品。多麼糟糕的錯誤>。<非常感謝您的提示:) – Roman