CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 8/30/2007 9:07:54 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 7 Views: 53 Favorited: 0 Favorite
8 Items, 1 Pages 1 |< << Go >> >|
cecook05
Asp.Net User
How to change user control label that is in master page8/30/2007 9:07:54 PM

0/0

I have a masthead user control (see below) in a master page.  The user control has a label control in it.  In the past I had the user control in each of my pages and I would pass a value to the usercontol as part of the control definition.  That value then was used as the text of the label.  I'm trying to use a master page now and have the user control be a part of the master page instead of added to each individual page.  My question is, how do I pass a value to the user control from my individual pages (that use the master page)?

namespace CCdotNet
{
    public partial class masthead : System.Web.UI.UserControl
    {
        private string m_title = string.Empty;
        public string pageTitle
        {
            get { pageTitle = m_title; return pageTitle; }
            set { m_title = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.lblPageTitle.Text = this.m_title;
            }
        }
    }
}

 
wortho
Asp.Net User
Re: How to change user control label that is in master page8/30/2007 9:37:23 PM

0/0

What I have done in the past is have a base class for my master pages. Then they all inherit from this.

Then each content page has a reference to the base class too, now in the page load of the content page, you can set the shared property of the master page.

Then in the Master page load, you can read those properties to the user control. ie;

In you App_Code you have this  class;

public class BaseWebUIMasterPage : MasterPage

{

private String _mastheadTitle;

public String MastHeadTitle

{

get {return _mastheadTitle;}

set {_mastheadTitle = value;}

}

}

Then in your master pages,

public partial class Masters_Cdb : BaseWebUIMasterPage

{

protected void Page_Load(object sender, EventArgs e)

{

// Set the control value

control1.pageTitle = MastHeadTitle;

}

 

Then in each content page, have this in the top

<%@ MasterType TypeName="BaseWebUIMasterPage" %>

 

Then in the page load of each content page, you can access the property Master.MastHeadTitle = "my page title"

And in the master page it will set the control value.

We find this really extensable.

Hth,

Cheers,

Steve


Please remember to 'Mark as Answer' if this post answered your question!
ian.coetzer
Asp.Net User
Re: How to change user control label that is in master page8/30/2007 9:48:07 PM

0/0

Hi, this is an easy one!

 If you are within a usercontrol, that resides inside a page, which in turn uses a masterpage with say a Label called Label1, then you can use the code below to change the text on the label on this masterpage as shown below (tested this just now so it works!)

            if (this.Page.Master != null)
            {
                Label lbl = (Label)this.Page.Master.FindControl("Label1");
                lbl.Text = "Hello World!";
            }

Now! If you are not within a user control, but rather in a page that is using a masterpage, then your code will look a little different: 

            if (this.Form.Parent != null)
            {
                Label lbl = (Label) this.Form.Parent.FindControl("Label1");
                lbl.Text = "Hello World!";
            }
 
I.W Coetzer
cecook05
Asp.Net User
Re: How to change user control label that is in master page8/30/2007 10:21:38 PM

0/0

Steve I get an error when I run the page.  I created an app_code folder and added the class.

Parser Error Message: Could not load type 'BaseWebUIMasterPage'.

Source Error:

Line 1:  <%@ Page Language="C#" MasterPageFile="~/ccdotnet.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CCdotNet.index" Title="Untitled Page" %>
Line 2:  <%@ MasterType TypeName="BaseWebUIMasterPage" %>
Line 3:  
Line 4:  

 using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace CCdotNet
{
    public class BaseWebUIMasterPage : MasterPage
    {
        private String _mastheadTitle;

        public String MastHeadTitle
        {

            get { return _mastheadTitle; }

            set { _mastheadTitle = value; }

        }

    }
}
------------------------------------------------
 for master page:
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace CCdotNet
{
    public partial class ccdotnet : BaseWebUIMasterPage
 

 

wortho
Asp.Net User
Re: How to change user control label that is in master page8/30/2007 10:34:33 PM

0/0

That would be your namespace there at a quick guess!

<%@ MasterType TypeName="CCdotnet.BaseWebUIMasterPage" %>


Please remember to 'Mark as Answer' if this post answered your question!
cecook05
Asp.Net User
Re: How to change user control label that is in master page8/30/2007 11:17:03 PM

0/0

 OK, I took the namespace entry out of the class definition for BaseWebUIMasterPage and it works now.  Thanks!!!

cecook05
Asp.Net User
Re: How to change user control label that is in master page8/31/2007 6:43:47 PM

0/0

The solution above only works when I use a namespace on all of my code behind files.  If I don't use a namespace for my code behind I get the error below.  Is there something I can do so I don't have to use namespace?

Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.ccdotnet_master' to type 'BaseWebUIMasterPage'.

Source Error:

Line 28:     public new BaseWebUIMasterPage Master {
Line 29:         get {
Line 30:             return ((BaseWebUIMasterPage)(base.Master));
Line 31:         }
Line 32:     }

Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ccdotnet\28ad3fa4\9c5171ef\App_Web_coding.aspx.cdcab7d2.bivua_p9.0.cs    Line: 30

Stack Trace:

[InvalidCastException: Unable to cast object of type 'ASP.ccdotnet_master' to type 'BaseWebUIMasterPage'.]
   coding.get_Master() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ccdotnet\28ad3fa4\9c5171ef\App_Web_coding.aspx.cdcab7d2.bivua_p9.0.cs:30
   coding.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\ccdotnet\coding.aspx.cs:16
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

cecook05
Asp.Net User
Re: How to change user control label that is in master page8/31/2007 8:51:38 PM

0/0

I found my problem.  There was a dll for my namespace in the bin directory.  I deleted it and removed the namespace entries from all my code and all is well.

8 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007
Beginning ASP.NET 3.5: In C# and VB Authors: Imar Spaanjaars, Pages: 734, Published: 2008
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Pro ASP.NET for SQL Server: High Performance Data Access for Web Developers Authors: Brennan Stehling, Pages: 408, Published: 2007
Expert C# 2005 Business Objects Authors: Rockford Lhotka, Pages: 668, Published: 2006
Microsoft Sharepoint: Building Office 2007 Solutions in C# 2005 Authors: Scot Hillier, Pages: 513, Published: 2007
ASP.NET 2.0 Everyday Apps For Dummies Authors: Doug Lowe, Pages: 504, Published: 2006
Learning ASP.NET 3.5 Authors: Jesse Liberty, Dan Hurwitz, Brian MacDonald, Pages: 576, Published: 2008

Web:
ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps Apr 11, 2006 ... In fact, the MasterPage class derives from the UserControl class. .... job for a master page, so we will add a label control to our master. ...
How to: Customize the Variations Label Control Logic Each of the default master pages that are available in Microsoft Office SharePoint ... The variation label control is a user control on a variation page . ...
CodeProject: Inside Master Pages. Free source code and programming ... Master pages are actually user controls. When you see the code file of ..... Let ’s say I want to change two controls:. Label on the childMaster master page. ...
Referring to a control on a master page - ASP.NET Forums In that UserControl is a Button control. In that Button's Click event, I want to change the Text property of the Label control on the master ...
change master page labels from content page - telerik Forum the changes that you made to the masterpage labels from the login page. 'if logged in. ' get cart info for logged-in user . ...
Can't access label in MasterPage I'm having a problem with a label in a MasterPage which is not in a ContentPlaceHolder. The naughty label will not allow me to change its ...
ASP.NET Master Pages Tips and Tricks Figure 2: exposing a Label control in a master page through a public property. .... NET 2.0 derives from UserControl and just like user controls, master ...
Update a label on a Master Page in .Net 2.0 : ASP.Net, 2.0 I have a master page on which I have a label. I would like to change the value of this ..... The master page is actually a user control in the page, ...
ASP.Net Tutorial - Beginner's Guide to Master Pages (ASP.Net ... You can do this with any DotNet control you put on the Master Page. Let's say you also have a label control at the bottom of your Master page, ...
FIND CONTROLS IN AN ASP.NET PAGE WITH A MASTERPAGE | Dev102.com Mar 17, 2008 ... NET APPLICATION WITH A MASTERPAGE, ALL THE CONTROLS RECEIVE A ... I have 5 User Controls i one page, and I try to find label for error ...




Search This Site:










dotnetnuke 3.2 treeviewmenu changes?

upgrade steps for dnn 2.0.4 to 2.1.2?

please help.... ugraded 3.0.7 to 3.0.8 --host login not working

ms access 97 2000 database in dotnetnuke?

what files are required for hosted dnn to function?

skins preview images don't display

custom module development

bug - register link does not point to register page! need help!

host settings unavailable after shift to remote

help with modifying cute html providor

dotnetnuke custom module testenvironment ?

dnn vs sharepoint

does asp 2.0 make dnn not necessary?

skinswitcher module

pivotal modules

form application

having problem accessing dotnetnuke's database

http error 403 - forbidden

free textbox

compressing .js and .css files (iis 6.0)

re-building dotnetnuke 3 in vs.net 2003

images not showing up on skin or containers in w2k3 but work fine in xp/2k

dnn 2.0.3 deleted tab still visible

skinning is the best thing since sliced cheese

bug: 3.1 dotnetnuke.search.datastore.getsearchwords

url of simple container skins

dnn-2.0 module actions

dnnswf flash viewer v2

fckeditor value property not getting set

"border" config problem

  Privacy | Contact Us
All Times Are GMT