• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

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)
0
kdeutsch
Asked:
kdeutsch
  • 2
  • 2
1 Solution
 
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
 
kdeutschAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now