0

我有一个从 MSDN 复制的 asp.net 表单上传框。提交表单后,我希望页面使用 2 个查询参数重定向,而不是在页面上显示信息,文件名和一个隐藏表单字段的数字,在同一个表单和上传框中。表单提交后如何获取该号码以添加到重定向代码。我的表单字段名称是“id”

<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs)

    If FileUpload1.HasFile Then
        Try
            FileUpload1.SaveAs("C:\inetpub\sites\rebbetzin\uploads\" & _
               FileUpload1.FileName)
            Label1.Text = "File name: " & _
               FileUpload1.PostedFile.FileName & "<br>" & _
               "File Size: " & _
               FileUpload1.PostedFile.ContentLength & " kb<br>" & _
               "Content type: " & _
               FileUpload1.PostedFile.ContentType

                Response.Redirect("http://www.rebbetzins.org/thanks.asp?id=" &  ______ & "&f=" & FileUpload1.PostedFile.FileName )
        Catch ex As Exception
            Label1.Text = "ERROR: " & ex.Message.ToString()
        End Try
    Else
        Label1.Text = "You have not specified a file."
    End If
End Sub

4

2 回答 2

0

request.form("id") 应包含该隐藏表单字段中的值。

于 2013-08-19T17:24:22.497 回答
0

该值存储在Request.Form集合中,如下所示:

Request.Form("id")

所以你的Response.Redirect代码应该是这样的:

Response.Redirect("http://www.rebbetzins.org/thanks.aspx?id=" & Request.Form("id") & "&f=" & FileUpload1.PostedFile.FileName )

注意:该thanks页面是一个.aspx而不是.asp扩展,对吧?我在答案中将其更改为.aspx

更新:

由于您有一个 ASP.NET 服务器控件来保存隐藏值,因此您可以这样做:

Me.id2.Value

所以你的Response.Redirect遗嘱现在看起来像这样:

Response.Redirect("http://www.rebbetzins.org/thanks.aspx?id=" & Me.id2.Value & "&f=" & FileUpload1.PostedFile.FileName )

更新 2:

要在页面中填充 ASP.NET HiddenField 控件thanks.aspx,您需要从事件中的查询字符串中读取它Page_Load,如下所示:

Protected Sub Page_Load(sender As Object, e As EventArgs)
    If Request.QueryString("id") IsNot Nothing Then
        Me.id2.Value = Request.QueryString("id")
    End If
End Sub
于 2013-08-19T17:29:29.973 回答