Link to home
Create AccountLog in
Avatar of WesleyAlgee
WesleyAlgee

asked on

master pages and content pages passing information between the two

I am brand new to master pages and maybe I do not have the correct concept of how they work. I have a master page that contains my buttons save, delete, and edit I have a content page that contains my textboxes. when I click on my save button and try to save the information that is on my content pages I get the error object not found I am trying to use findcontrol but that does not seem to work how can I pass information between master and content pages? I am using visual studio 2008 if that matters
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Which direction are you talking about?  From the master page to the content page?  Or, from the content page to the master page?

With strong-typed master pages, you can easily reference public elements from the content page.

Passing Information Between Content and Master Pages
http://aspnet.4guysfromrolla.com/articles/013107-1.aspx

Bob
Avatar of WesleyAlgee
WesleyAlgee

ASKER

I have looked at that but when I try and follow the example and subscribe to the event in the content page like this
AddHandler Master.MoodChanged, AddressOf MoodChangedFromMasterPage
 I have a message that says
moodchangedfromMasterPage is not delcared
Did you define an event handler for MoodChangedFromMasterPage for the content page?

Bob
I am going to attach my code for you to look at my error message now says InformationSave is not an event of system.web.ui.masterpage
'THIS IS MY MASTER PAGE
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Public Class MasterPDFQuote
    Inherits System.Web.UI.MasterPage
    Protected WithEvents btnSaveemail As System.Web.UI.WebControls.Button
    Protected WithEvents btnSave As System.Web.UI.WebControls.Button
    Protected WithEvents btnDelete As System.Web.UI.WebControls.Button
    Protected WithEvents btnClose As System.Web.UI.WebControls.Button
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Public Event InformationSave As CommandEventHandler
    Dim conn As New SqlConnection
    Protected Sub OpenDataBase()
        If Session("DBConn") <> "" Then
            conn = New SqlConnection(Session("DBConn"))
        Else
            Response.Write("<script language=javascript>alert('This page expired.');")
            Response.Write("window.close();</script>")
            Response.End()
        End If
 
        conn.Open()
    End Sub
    Protected Sub CloseDatabase()
        conn.Close()
        conn = Nothing
 
    End Sub
    Public Function repSingle(ByVal Str1 As String) As String
        Dim str2 As String
        str2 = Replace(Str1, Chr(39), Chr(39) & Chr(39))
        Return str2
 
    End Function
 
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("DBConn") = "" And Session("ThisCorporation") <> "" Then
            StartConn(Session("ThisCorporation"))
            Session("DocumentPath") = Module2.DocumentPath
            Session("webroot") = Module2.WebRoot
            Session("DocFolder") = Module2.DocFolder
            Session("DBConn") = Module2.DBConn
        ElseIf Session("webRoot") <> "" Then
            WebRoot = Session("webroot")
            DocFolder = Session("DocFolder")
            DocumentPath = Session("DocumentPath")
        Else
            Response.Write("<script language=javascript>alert('This page expired.');windown.close;</script>")
            Response.End()
            Exit Sub
        End If
 
        btnSaveemail.Visible = True
        btnSave.Visible = True
        btnDelete.Visible = True
        btnClose.Visible = True
        btnCancel.Visible = True
 
    End Sub
 
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        RaiseEvent InformationSave(sender, e)
    End Sub
 
 
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'THIS IS MY CONTENT PAGE
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Public Class PDFQuoteForm
    Inherits System.Web.UI.Page
    Public WithEvents lbl1 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl2 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl3 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl4 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl5 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl6 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl7 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl8 As New System.Web.UI.WebControls.Label
    Public WithEvents lbl9 As New System.Web.UI.WebControls.Label
    Public WithEvents content2 As New System.Web.UI.WebControls.Content
    Public WithEvents txtQuoteID As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtValidUntil As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtPaymentTerms As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtSalesRep As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtQuantity As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtDescription As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtUnitPrice As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtExtension As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtTermsandConditions As New System.Web.UI.WebControls.TextBox
    Public WithEvents txtNote As New System.Web.UI.WebControls.TextBox
    Public WithEvents dropdownlist1 As New System.Web.UI.WebControls.DropDownList
    Public WithEvents dropdownlist2 As New System.Web.UI.WebControls.DropDownList
    Public WithEvents dropdownlist3 As New System.Web.UI.WebControls.DropDownList
    Public WithEvents dropdownlist4 As New System.Web.UI.WebControls.DropDownList
    Dim conn As New SqlConnection
    Protected Sub OpenDataBase()
        If Session("DBConn") <> "" Then
            conn = New SqlConnection(Session("DBConn"))
        Else
            Response.Write("<script language=javascript>alert('This page expired.');")
            Response.Write("window.close();</script>")
            Response.End()
        End If
 
        conn.Open()
    End Sub
    Protected Sub CloseDatabase()
        conn.Close()
        conn = Nothing
 
    End Sub
    Public Function repSingle(ByVal Str1 As String) As String
        Dim str2 As String
        str2 = Replace(Str1, Chr(39), Chr(39) & Chr(39))
        Return str2
 
    End Function
 
    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        AddHandler Master.InformationSave, AddressOf InformationSave
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Session("DBConn") = "" And Session("ThisCorporation") <> "" Then
            StartConn(Session("ThisCorporation"))
            Session("DocumentPath") = Module2.DocumentPath
            Session("webroot") = Module2.WebRoot
            Session("DocFolder") = Module2.DocFolder
            Session("DBConn") = Module2.DBConn
 
        End If
 
        txtQuoteID.Visible = True
        txtValidUntil.Visible = True
        txtPaymentTerms.Visible = True
        txtSalesRep.Visible = True
        txtQuantity.Visible = True
        txtDescription.Visible = True
        txtUnitPrice.Visible = True
        txtExtension.Visible = True
        txtTermsandConditions.Visible = True
        txtNote.Visible = True
 
        OpenDataBase()
        Dim CMD As New SqlCommand
        CMD.CommandText = "select Top 1 GoodThrulabel, SalesRepLabel, CustomerIDLabel, " & _
                "PaymentTermsLabel, QuantityLabel, ItemNameLabel, DescriptionLabel, " & _
                "UnitPriceLabel, ExtensionLabel, TermAndConditionLabel, TermAndConditionText " & _
                "from BA_QuotePDFdesign "
        CMD.Connection = conn
        Dim DRpdf As SqlDataReader
        DRpdf = CMD.ExecuteReader
        If DRpdf.Read() Then
            txtQuoteID.Text = DRpdf.Item("CustomerIDLabel")
            txtValidUntil.Text = DRpdf.Item("GoodThrulabel")
            txtPaymentTerms.Text = DRpdf.Item("PaymentTermsLabel")
            txtSalesRep.Text = DRpdf.Item("SalesRepLabel")
            txtQuantity.Text = DRpdf.Item("QuantityLabel")
            txtDescription.Text = DRpdf.Item("DescriptionLabel")
            txtUnitPrice.Text = DRpdf.Item("UnitPriceLabel")
            txtExtension.Text = DRpdf.Item("ExtensionLabel")
            txtTermsandConditions.Text = DRpdf.Item("TermAndConditionLabel")
            txtNote.Text = DRpdf.Item("TermAndConditionText")
        End If
        DRpdf.Close()
        CMD.Dispose()
        CloseDatabase()
 
        Dim txtqid As String
        Dim txtvu As String
        Dim txtpt As String
        Dim txtsr As String
        Dim txtquant As String
        Dim txtdesc As String
        Dim txtup As String
        Dim txtext As String
        Dim txttac As String
        Dim txtn As String
 
        txtqid = txtQuoteID.UniqueID
        ViewState("vsqid") = txtqid
 
        txtvu = txtValidUntil.UniqueID
        ViewState("vsvu") = txtvu
 
        txtpt = txtPaymentTerms.UniqueID
        ViewState("vspt") = txtpt
 
        txtsr = txtSalesRep.UniqueID
        ViewState("vssr") = txtsr
 
        txtquant = txtQuantity.UniqueID
        ViewState("vsquant") = txtquant
 
        txtdesc = txtDescription.UniqueID
        ViewState("vsdesc") = txtdesc
 
        txtup = txtUnitPrice.UniqueID
        ViewState("vsup") = txtup
 
        txttac = txtTermsandConditions.UniqueID
        ViewState("vstac") = txttac
 
        txtn = txtNote.UniqueID
        ViewState("vsn") = txtn
 
    End Sub
    Private Sub InformationSave()
        OpenDataBase()
        Dim Cmd As New SqlCommand
        Cmd.Connection = conn
        Dim qry As String
 
        Dim t1 As String
        t1 = ViewState("vsqid")
        Dim tqid As TextBox = FindControl(t1)
 
        Dim t2 As String
        t2 = ViewState("vsvu")
        Dim tvu As TextBox = FindControl(t2)
 
        Dim t3 As String
        t3 = ViewState("vspt")
        Dim tpt As TextBox = FindControl(t3)
 
        Dim t4 As String
        t4 = ViewState("vssr")
        Dim tsr As TextBox = FindControl(t4)
 
        Dim t5 As String
        t5 = ViewState("vsquant")
        Dim tquant As TextBox = FindControl(t5)
 
        Dim t6 As String
        t6 = ViewState("vsdesc")
        Dim tdesc As TextBox = FindControl(t6)
 
        Dim t7 As String
        t7 = ViewState("vsup")
        Dim tup As TextBox = FindControl(t7)
 
        Dim t8 As String
        t8 = ViewState("vstac")
        Dim ttac As TextBox = FindControl(t8)
 
        Dim t9 As String
        t9 = ViewState("vsn")
        Dim tn As TextBox = FindControl(t9)
 
        qry = "update BA_QuotePDFdesign set GoodThrulabel = '" & repSingle(tvu.Text) & "', SalesRepLabel = '" & repSingle(tsr.Text) & "', CustomerIDLabel = '" & repSingle(tqid.Text) & "', PaymentTermsLabel = '" & repSingle(tpt.Text) & "', QuantityLabel = '" & repSingle(tquant.Text) & "', DescriptionLabel = '" & repSingle(tdesc.Text) & "', UnitPriceLabel = '" & repSingle(tup.Text) & "', TermAndConditionLabel = '" & repSingle(ttac.Text) & "', TermAndConditionText = '" & repSingle(tn.Text) & "'"
        Cmd.CommandText = qry
        Cmd.ExecuteNonQuery()
        CloseDatabase()
    End Sub
End Class

Open in new window

Do you have something like this in the content page's HTML view?

<%@ MasterType VirtualPath="~/MasterPage.master" %>

Bob
ok maybe that is my problem this is a nested masterpage situation I have the following masterpagefile="`/SubmasterPDFQuote.master" on my content page

here are the names of my pages
MasterPDFQuote.master (this page has Public Event InformationSave As CommandEventHandler)
SubMasterPDFQuote.master
PDFQuoteForm.aspx (this page has AddHandler Master.InformationSave, AddressOf InformationSave)
Yeah, 2005 didn't work with nested master pages in the designer, and I haven't looked at 2008 yet to see if it does.

What version are you working with?

Bob
I am using 2008
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Solution, or no solution?  I tried to help, and I would like to know the reason for deleting this.

Bob