webbrowser使用c在电话簿网页上动态链接

本文关键字:动态 链接 网页 电话簿 使用 webbrowser | 更新日期: 2023-09-27 18:28:39

我正在用c#编写一个程序。在上一张表格中,我得到了一个名为"电话簿"的按钮。当我按下它时,它应该打开一个网址为"tel.search.ch"(瑞士-德国网站;)的网络浏览器。我已经研究过这个网站的网址了。它是这样的:

tel.search.ch/?what=名字+姓氏&其中=客厅

但当我点击按钮时,它会打开网络浏览器,但url是这个网站的主页。因此,web浏览器导航到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;
            }
        }

我不知道为什么网络浏览器会导航到这个网站的主页。有人有主意吗?

欢呼

webbrowser使用c在电话簿网页上动态链接

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

变量forenamesurnamelivingplace未初始化。URL看起来像http://tel.search.ch/?what=+&where=。因此,你的URL(特别是查询字符串)不会被网站解析,而是重定向到主页。您可以通过放置一些静态值或初始化这些值来检查它。

即使您使用了错误的URL,也不要将+用于forename + "+" + surname。这将是:

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