Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to variables created in codebehind pageload

Status
Not open for further replies.

MdotButler

Programmer
Jan 18, 2006
104
0
0
US
I have a task where I need to create a FDF file for a PDF form from a database. In the PageLoad method of the VB CodeBehind I have the database access. I need to then create the variables and access them in the ASPX page. The following is the ASPX code.
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Encounter_P.aspx.vb" Inherits="Encounter_P" %>
<%  Response.ContentType = "application/vnd.fdf"%>
%FDF-1.2
1 0 obj
<<
/FDF
<< /Fields
[
<< /V (<%=strC_LocationName%>) /T (C_LocationName)>>
<< /V (<%=strC_LocationAddress1%>) /T (C_LocationAddress1)>>
<< /V (<%=strC_LocationAddress2%>) /T (C_LocationAddress2)>>
<< /V (<%=strC_LocationAddress3%>) /T (C_LocationAddress3)>>
]
/F ([URL unfurl="true"]https://www.xyz.com/TheForm.pdf)[/URL]
>>
>>
endobj
trailer
<</Root 1 0 R>>
%%EOF
The following is the CodeBehind that wil read the database and fill the variables needed in the above code.
Code:
Imports System.Data
Imports System.Data.SqlClient

Partial Class Encounter_P
    Inherits System.Web.UI.Page

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

        'database i/o here

        ' declare the variables used on the form...
        Dim strC_LocationName As String = "Name from DB"
        Dim strC_LocationAddress1 As String = "Address 1 from DB"
        Dim strC_LocationAddress2 As String = "Address 2 from DB"
        Dim strC_LocationAddress3 As String = "CSZ from DB"
    End Sub
I am not asking about the DB access just how to use the variables defined in the codebehind in the ASPX code. I know this must be simple but I have not had to do it before. Any help would be appreciated.

TIA
Mark
 
my vb is rusty, but it would look something like this.
you need public properties in the class so the page can access them.
Code:
Partial Class Encounter_P
    Inherits System.Web.UI.Page

    Public Property strC_LocationName As String = "Name from DB"
    Public Property strC_LocationAddress1 As String = "Address 1 from DB"
    Public Property strC_LocationAddress2 As String = "Address 2 from DB"
    Public Property strC_LocationAddress3 As String = "CSZ from DB"

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

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanx Jason....

The placement was correct the syntax should have been:
Code:
Public strC_LocationName As String = "Name from DB"
Thanx again for the help, I knew it had to be easy ;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top