开发者

sending a variable from code-behind to .aspx

How I can send a variable from code-behaind to .aspx file :

code-behind:

variable 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>

How I can send FilePathName to src in .aspx

Thanks,

Ahmed.

*********** U P D A T E ***********

This is Code-Behind and my goal is to open .pdf file in a frame so that I can open together with another .htm page in one window:

    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

I'm remarking last rows because I don't want .pdf file to be opened outside the web page.


You may use a asp:Literal as container for your frame's HTML, or use the <%= Variable %> tag... Solution 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 + "\">";

Solution 2 : In ASPX :

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

PS : frames are deprecated in web since more than 10 years...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜