注册 登录
编程论坛 ASP.NET技术论坛

关于两aspx页面通讯问题

heruting 发布于 2008-10-26 21:05, 1053 次点击
有个两个aspx网页要进行通讯,第一个网页点击提交按钮后在第二个网页中现实前一个网页提交的内容,可是编译没问题,可是调试的时候老是出错,求高人指点,我这个程序是用VB写的
第一个网页:  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim url As String
        url = "webform3.aspx?name=" + TextBox1.Text + "&password=" + TextBox2.Text + "&age=" + DropDownList1.SelectedItem.Selected + "&brithday=" + Label11.Text + "&email=" + TextBox4.Text + "&Sex=" + RadioButtonList1.SelectedItem.Selected + "&Explanation=" + TextBox5.Text

        Page.Response.Redirect(url)
    End Sub
第二个网页:
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码

        Label9.Text = Request.QueryString("name").ToString
        Label10.Text = Request.QueryString("password").ToString


    End Sub
IIS错误提示:异常详细信息: System.FormatException: 输入字符串的格式不正确
我的那个URL那里该怎么写?
2 回复
#2
铲铲2008-10-27 09:53
通过URL传递参数,最好将其进行URL编码,对非英文字符转换为形如%E5A5%30D6类似的字符串。

具体是改进如下语句:
url = "webform3.aspx?name=" + Server.UrlEncode(TextBox1.Text) + "&password=" + Server.UrlEncode(TextBox2.Text) + "&age=" + Server.UrlEncode(DropDownList1.SelectedItem.Selected) + "&brithday=" + Server.UrlEncode(Label11.Text) + "&email=" + Server.UrlEncode(TextBox4.Text) + "&Sex=" + Server.UrlEncode(RadioButtonList1.SelectedItem.Selected) + "&Explanation=" + Server.UrlEncode(TextBox5.Text)

Server.UrlEncode针对非因英文字符集,且用this.Request["参数名"]获得参数时,它会自动使用Server.UrlDecode解码,无需人工干预
#3
heruting2008-10-27 12:31
哦,非常感谢楼上的解答
1