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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update masterpage from App_Code files

Status
Not open for further replies.

PoppapumpJ

Programmer
Dec 17, 2001
86
US
I apologize if this is somewhere else and I've just missed it.

I have a footer (label control) in my MaterPage that I use to display any errors that occur during the processing of a transaction.

I have opened this label control as a public property in the master page and I can add text to the control from my regular pages.

My problem is that I would like to display errors that occur in some of my globally accessable functions which reside in the App_Code.

Since items in App_Code can't see the items outside of it, I'm having trouble dsplaying these messages.

So far, the best I have come up with is to put the messages in a collection stored as a session variable. The Master page then reads from the session variable. It works... but it just doesn't feel right.

Thanks for the help.
 
Pass the masterpage the object in your App_Code directory and set the error messages. or better yet, use a view and remove any requirement to the web.
Code:
IErrorsView
{
   string[] Errors {set;}
}

MyMasterPage : MasterPage, IErrorsView
{
   public string[] Errors
   {
      set   
      {  
         controlToDisplayErrors.DataSource = value;
         controlToDisplayErrors.DataBind();
      }
   }
}

public class MyControlToCollectErrors
{
    //...other members
    void DisplayErrorsTo(IErrorsView view)
    {
        view.Errors = GetArrayOfErrors();
    }
}
then somewhere in your code pass the Master page to the function.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks Jason,

I guess what I am having trouble with is passing the object to the masterpage.

Items in the App_Code are not really part of the Page namespace...So I'm having trouble hooking into the in-use instance of the master page.

Sorry if I'm not using the correct vocabulary..I'm fairly new to .NET.
 
by using an interface and having the master page inherit the interface you don't need references to System.Web.

from the Master page you could do
[tt]instanceOfMyControlToCollectErrors.DisplayErrorsTo(this);[/tt]
from a Page it would look like this
[tt]instanceOfMyControlToCollectErrors.DisplayErrorsTo((MyMasterPage)Master);[/tt]
from another object type of object, which is not a page or master
[tt]instanceOfMyControlToCollectErrors.DisplayErrorsTo(theObject.PropertyOfTypeIErrorsView);[/tt]



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top