Master page label not found on common code page

For the new update panel stuff I wrote a error label on my master page that I pass the error to in a try catch when i look for data, but I always have to put in all the Dim statements.  i want to put them on my Common code page with other variables I use but it does not seem to find the labels, how can i change the sytax to find the labels on the master page.

Current method put into every try catch statement
  Dim lblErrorMsg As Label = DirectCast(Me.Master.FindControl("lblErrorMsg"), Label)
        Dim aError As HtmlAnchor = DirectCast(Me.Master.FindControl("aError"), HtmlAnchor)
        Dim lblError As Label = DirectCast(Me.Master.FindControl("lblError"), Label)

 Try
            insertUpdateDelete(sql)
        Catch ex As Exception
            lblError.Text = ex.Message.ToString & " - ERROR Add Personnel  < br > " & lblErrorMsg.Text
            SetFocus(aError)
        End Try


New method I would like.
Put dim statements on Common code page and keep try catch as is.
When I put these on the page it gives me blue underline on the ME.
take this out and it gives it under the Findcontrol and so on.

 Public Shared lblErrorMsg As Label = DirectCast(Me.Master.FindControl("lblErrorMsg"), Label)
    Public Shared aError As HtmlAnchor = DirectCast(Me.Master.FindControl("aError"), HtmlAnchor)
    Public Shared lblError As Label = DirectCast(Me.Master.FindControl("lblError"), Label)
kdeutschAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gamarrojgqCommented:
Hi,

Your Common Code Page have setting the Same Master Page than the Other Pages? or when you said Common code Page you mean a Class File that just contains code?
0
kdeutschAuthor Commented:
gamarrojgq:
i mean a class file that just contains code.
0
gamarrojgqCommented:
ok that is why you  cannot use Me.Master since this only will work for pages.

If you want to use an external class file you should pass at least the Me.Master  object to the class, something like this

  Catch ex As Exception
            YourClasss.SetErrorMessage( Me.Master, ex.Message )
            'lblError.Text = ex.Message.ToString & " - ERROR Add Personnel  < br > " & lblErrorMsg.Text
            'SetFocus(aError)
        End Try


And  in your class the SetErrorMessage will use the Me.Master To Find the Controls

Public Sub SetErrorMessage(objMaster As Object, strErrMessage as string)

        Dim lblErrorMsg As Label = DirectCast(objMaster.FindControl("lblErrorMsg"), Label)
        Dim aError As HtmlAnchor = DirectCast(objMaster.FindControl("aError"), HtmlAnchor)
        Dim lblError As Label = DirectCast(objMaster.FindControl("lblError"), Label)

        lblError.Text = strErrMessage & " - ERROR Add Personnel  < br > " & lblErrorMsg.Text

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kdeutschAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.