从代码隐藏到.aspx发送变量

时间:2010-12-25 22:23:03

标签: asp.net vb.net


如何将代码行为中的变量发送到.aspx文件:

代码隐藏:
变量 FilePathName

的.aspx:

<body>
<form id="form1" runat="server">
<div>
    <asp:TextBox ID="TextBox1" runat="server" Text="Label"></asp:TextBox>
    <frameset cols="100%,*">
        <frame name="main" target="main" src="FilePathName">
    </frameset>

</div>
</form>

如何在.aspx

中将FilePathName发送到src

谢谢,
艾哈迈德。

** * ** * ** * 的** 更新 ** * ** * ** * **
这是Code-Behind,我的目标是在一个框架中打开.pdf文件,以便我可以在一个窗口中与另一个.htm页面一起打开:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim sFilePath As String
    Dim buffer As Byte()
    Using con As New SqlConnection()
        con.ConnectionString = ConfigurationManager.ConnectionStrings()("SqlServerConnection").ConnectionString
        con.Open()
        Using cmd As New SqlCommand("SELECT imageLaw FROM Laws WHERE ID = @ID", con)
            Dim pID As New SqlParameter("@ID", SqlDbType.Int)
            pID.Value = CType(Request.QueryString("pID"), Integer)
            cmd.Parameters.Add(pID)
            buffer = cmd.ExecuteScalar()
        End Using
        con.Close()
    End Using
    sFilePath = System.IO.Path.GetTempFileName()
    System.IO.File.Move(sFilePath, System.IO.Path.ChangeExtension(sFilePath, ".pdf"))
    sFilePath = System.IO.Path.ChangeExtension(sFilePath, ".pdf")
    System.IO.File.WriteAllBytes(sFilePath, buffer)
    'Literal1.Text = "<frame  src=\"" + sFilePath + " \ ">"

    'TextBox1.Text = sFilePath
    ' ''Response.WriteFile(sFilePath)
    ' ''Response.End()
    ' ''Response.BinaryWrite(buffer)
    'Dim act As Action(Of String) = New Action(Of String)(AddressOf OpenFilePW)
    'act.BeginInvoke(sFilePath, Nothing, Nothing)
End Sub

Private Shared Sub OpenFilePW(ByVal sFilePath As String)

    Using p As New System.Diagnostics.Process
        p.StartInfo = New System.Diagnostics.ProcessStartInfo(sFilePath)
        p.Start()
        p.WaitForExit()
        Try
            System.IO.File.Delete(sFilePath)
        Catch
        End Try
    End Using
End Sub

我正在评论最后一行,因为我不希望在网页外打开.pdf文件。

1 个答案:

答案 0 :(得分:1)

您可以使用asp:Literal作为框架HTML的容器,或使用&lt;%= Variable%&gt;标签... 解决方案1:

<frameset cols="100%,*">
<asp:Literal ID="litFrame" runat="server"></asp:Literal>
</frameset>

and in CB : litFrame.Text = "<frame name=\"main\" target=\"main\" src=\"" + FilePathName + "\">";

解决方案2: 在ASPX中:

<frameset cols="100%,*">
<frame name="main" target="main" src="<%= myTarget %>">";
</frameset>

PS:超过10年以来,网页已被弃用......