CodeVerge.Net Beta


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

ASP.NET Web Hosting – 3 Months Free!



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: 10/3/2007 9:51:50 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 30 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
slinkycurtis
Asp.Net User
Accessing user controls from pages within Master pages10/3/2007 9:51:50 AM

0/0

Hi,

 I have a problem with a web-site I have built which users Master Pages.  One of the pages has a userControl within it, and in the codebehind on the page being loaded into the master page, I access methods and properties on this control.  All builds fine.

When I run it, the control does not load, and looking at the source code, the reason is that the control is prefixed with the name of the container of the master page, "ctl00_contentPage" which stops this control loading properly.  As soon as I amend the HTML generated and delete this prefix from the control name it works fine!

Any ideas?

Thanks

Paul

naturehermit
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 11:12:04 AM

0/0

Use Control.ClientId to get the correct Id


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
slinkycurtis
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 11:28:13 AM

0/0

Ok, I can see how using Control.ClientID would get me the server control identifier, but how should this be used in the code behind for my page being loaded into the master page?  To give you more of an idea, I am using a map userControl in my page, and have code like:-

HotelMap.ClearPins();
HotelMap.Zoom = 10;
HotelMap.RegisterMap();

within the page to access properties and methods of that user control.  This control ID gets modified at run-time, so how would I use the ClientID property in this context?

 Thanks for replying...

naturehermit
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 11:54:51 AM

0/0

Can i look at your complete code, where you are accessing it so that I can guide you. Please include details. ClientId will provide the actual id on the client.


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
slinkycurtis
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 12:16:30 PM

0/0

No Problem.

The masterpage contains the following element into which the other pages are loaded:-

<div id="contentmiddle">

<asp:contentplaceholder id="contentPage" runat="server">

</asp:contentplaceholder>

</div>

The page location.aspx being loaded into the masterpage contains the following page directives:-

<%@ Page Language="C#" MasterPageFile="~/EjMasterPage.master" AutoEventWireup="true" CodeFile="location.aspx.cs" Inherits="location" Title="Location page" %>
<%
@ MasterType TypeName="EjMasterPage" %>
<%
@ Register Src="LiveMap.ascx" TagName="LiveMap" TagPrefix="uc1" %>

The control is loaded into the page in the following code within the <BODY> of the page

<div>
     <uc1:LiveMap ID="HotelMap" runat="server" />
</div>

In the codebehind for location.aspx, the following code accesses properties and methods of this control:-

HotelMap.ClearPins();
HotelMap.Zoom = 10;

foreach (Photo photo in Photos.PhotoCollection)
{
   
if (photo.Latitude != 0)
    {
         HotelMap.AddPin("<img src=" + photo.SmallUrl + " />", photo.Title, Convert.ToDouble(photo.Latitude), Convert.ToDouble(photo.Longitude), "images/camera.jpg");
    }
}

HotelMap.RegisterMap();

 

The HotelMap control creates javascript which is injected into the head of the page in the RegisterMap() method.

The resultant page fails to load this control because the reference to the control above gets changed to:-

<div class="map contain">
	<div class="mapBorder">
		<div id="ctl00_contentPage_HotelMap_Map" style="height:300px;width:300px;position:absolute;">	
                                </div>		
                </div>
</div>
Let me know if you need more info and apologies for the length of the post!
slinkycurtis
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 12:30:26 PM

0/0

Hold on.....

 The problem is with the control that is generating the javascript loaded into the head tag - changing this to this.ClientID should do the trick.....

Think you've nailed it, will test and mark as answered soon after!

Thanks....

 Paul

naturehermit
Asp.Net User
Re: Accessing user controls from pages within Master pages10/3/2007 1:07:40 PM

0/0

Include <%=UserControlName.ClientId%> in javascript and thats it. Is it sorted?


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Microsoft Office SharePoint Server 2007: The Complete Reference Authors: David Matthew Sterling, David Sterling, Pages: 788, Published: 2007
Essential SharePoint 2007: A Practical Guide for Users, Administrators and Developers Authors: Jeff Webb, Pages: 428, Published: 2007
Professional ASP.NET 2.0 Databases Authors: Thiru Thangarathinam, Pages: 504, Published: 2007
Professional ASP.NET 2.0 XML Authors: Thiru Thangarathinam, Pages: 566, Published: 2005
ASP.NET 2.0 Website Programming: Problem-design-solution Authors: Marco Bellinaso, Pages: 576, Published: 2006
Beginning ASP.NET 2.0 E-commerce in C# 2005: From Novice to Professional Authors: Cristian Darie, Karli Watson, Pages: 681, Published: 2005
Microsoft Visual C# 2005 Unleashed Authors: Kevin Hoffman, Pages: 692, Published: 2006
Beginning ASP.NET 2.0 Authors: Chris Hart, John Kauffman, Chris Ullman, David Sussman, Pages: 759, Published: 2005
Beginning Visual C# 2005 Authors: Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White, Pages: 1062, Published: 2006
ASP.NET 2.0 MVP Hacks and Tips Authors: David Yack, Joe Mayo, Scott Hanselman, Fredrik Normén, Dan Wahlin, J. Ambrose Little, Jonathan Goodyear, Pages: 400, Published: 2006

Web:
Master Pages: Master Your Site Design with Visual Inheritance and ... More importantly, however, there is no built-in way to use user controls to satisfy any .... Within these ContentPlaceHolder controls, Master Pages can add ...
Master Pages and Site Navigation : The Official Microsoft ASP.NET Site NET pages within that folder. Additionally, each folder contains a ... Create a folder in the website called UserControls and add to that a new item of type ...
Visual Studio Magazine Online | Feature: Create Master Pages in ... NET, you were forced to embed user controls in every page to get consistency. .... NET controls on a master page by accessing properties within the new ...
Master Pages and Usercontrols - object reference not set - .NET ASP Master Pages and Usercontrols - object reference not set. ... to access a property from the Continents usercontrol and is done using ...
ASP.NET Master Pages Tips and Tricks NET 2.0 derives from UserControl and just like user controls, master pages can't be shared across IIS applications. There are a few different solutions that ...
ASP.NET v2.0 V: Master pages and navigation :: DotNetJohn Nov 14, 2007 ... Note that as per user controls embedded in pages the order of events is ... page have a property Master allowing access to the master page. ...
Master Page Inheritance and User Controls - Rick Strahl's Web Log I didn't try to access the main master directly from the pages or user controls -- maybe that will work with master.parent.master or something. ...
Master Pages and Navigation Because events can be present in both the master and content pages, the event order follows that of User Controls. So, for events that are captured twice, ...
Web Site Consistency Made Easy with ASP.NET 2.0 Master Pages The hierarchy of access to the Controls collection within the Page, MasterPage, ... Notice that Master Pages, along with user controls, are among resource ...
CodeProject: Inside Master Pages. Free source code and programming ... Master pages are actually user controls. When you see the code file of your master ... To access controls inside the master page, there are two methods: ...




Search This Site:










program technique: databinding, multi-query, filesdownload..

writing a .cs file i can use over many other programs

how can i create forums in asp.net

execution time

calendar

asp:button hover color change

how do you auto insert date & time seperate in .net

auto numbers

search into a base64 string

theoretical question.

visual web developer code files

how to move code from .aspx script section to code behind file

add div to asp.net page

what is difference?

how to call a vbs file from an asp?

no dataset in asp.net 2.0?

abstract/interface class

win apps counterpart site to asp.net?

pop message to user

graphics - such as some xp style icons

httpwebrequest and excel

how can i run the third party application from my web application?

varybycontrol & varybyparam

help: is the dynamically bound event persistent with session?

setting timeout

'profile': member names cannot be the same as their enclosing type

software to creat a live demo on my web application

where to place this code?

want to learn asp.net....

how to launch .swf with dynamically built parameters

  Privacy | Contact Us
All Times Are GMT