<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx</link><description>K. Scott Allen has an awesome blog and regularly publishes great articles on .NET topics (I've linked to a lot of them in the past). Last year he published a great ASP.NET 2.0 Master Pages Introduction that you can read here . Last week he published an</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>master pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#4272549</link><pubDate>Mon, 01 Oct 2007 18:26:48 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4272549</guid><dc:creator>DotNetKicks.com</dc:creator><author>DotNetKicks.com</author><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4272549" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#2052790</link><pubDate>Sun, 18 Mar 2007 07:08:10 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2052790</guid><dc:creator>Christopher Schick</dc:creator><author>Christopher Schick</author><description>&lt;p&gt;I use a technique similar to Forrrest's.&lt;/p&gt;
&lt;p&gt;Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If Not Page.IsPostBack Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim script As String&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim paths() As String = {Page.MapPath(&amp;quot;~/javascript/my.js&amp;quot;)}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim content As ContentPlaceHolder = DirectCast(Page.Form.FindControl(&amp;quot;ContentPlaceHolder1&amp;quot;), ContentPlaceHolder)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;script = GetValidJavaScript(content.Controls, paths, False)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), &amp;quot;MyKey&amp;quot;, script, True)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Sub&lt;/p&gt;
&lt;p&gt;' Loops through a control collection using recursion. &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;' Returns the javascript file with correct client control ids.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;' To use this function, use the server side control ids in the javascript file.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;' i.e. document.getElementById('serverControlId') or $('serverControlId')&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Public Function GetValidJavaScript(ByVal _parent As Object, ByVal paths() As String, Optional ByVal optimize As Boolean = True) As String&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim sb As StringBuilder = New StringBuilder()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim tr As TextReader&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim idx As Integer = 0&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For idx = 0 To paths.GetUpperBound(0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr = New StreamReader(paths(idx))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If Not sb Is Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Append(tr.ReadToEnd())&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Append(Environment.NewLine + tr.ReadToEnd())&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Close()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IterateThroughControls(_parent, sb, optimize)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catch ex As Exception&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return ex.ToString() + Environment.NewLine + ex.InnerException.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return sb.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Private Function IterateThroughControls(ByVal _myParent As ControlCollection, ByVal sb As StringBuilder, ByVal optimize As Boolean) As String&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim ctrl As Control&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For Each ctrl In _myParent&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If Not String.IsNullOrEmpty(ctrl.ID) And Not String.IsNullOrEmpty(ctrl.ClientID) Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Replace(&amp;quot;'&amp;quot; + ctrl.ID + &amp;quot;'&amp;quot;, &amp;quot;'&amp;quot; + ctrl.ClientID + &amp;quot;'&amp;quot;) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If ctrl.Controls.Count &amp;gt; 0 Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IterateThroughControls(ctrl.Controls, sb, optimize)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catch ex As Exception&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return &amp;quot;Recursion Error: &amp;quot; + ex.ToString() + Environment.NewLine + ex.InnerException.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Try&lt;/p&gt;
&lt;p&gt;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If optimize Then&lt;/p&gt;
&lt;p&gt;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim strResult As String &lt;/p&gt;
&lt;p&gt;' = OptimizeScript(sb.ToString())&lt;/p&gt;
&lt;p&gt;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return strResult&lt;/p&gt;
&lt;p&gt;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return sb.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Function&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2052790" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#2034555</link><pubDate>Thu, 15 Mar 2007 18:12:16 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2034555</guid><dc:creator>Khan</dc:creator><author>Khan</author><description>&lt;p&gt;I have a calendar popup used at many a places in in my application. when i popup the calendar from a webpage which is inherited from masterpage it wont populate the textbox with date back.... can anyone help me out... same code works for a webpage which is not inherited from masterpage.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2034555" width="1" height="1"&gt;</description></item><item><title>Moving from design to reality - building HedKandi.com in Microsoft Office SharePoint Server 2007</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#725248</link><pubDate>Wed, 25 Oct 2006 08:30:52 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:725248</guid><dc:creator>Enterprise Content Management (ECM) Team Blog</dc:creator><author>Enterprise Content Management (ECM) Team Blog</author><description>&lt;p&gt;As mentioned in my blog entry from a few weeks ago, cScape Ltd , a Microsoft Gold Partner, recently launched&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=725248" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#671871</link><pubDate>Mon, 16 Oct 2006 14:16:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:671871</guid><dc:creator>John King</dc:creator><author>John King</author><description>Hi:

I now have Forrest's idea incorporated into my app and it works great. The trick now is to insert the related javascript functions into the head section of the document without embedding them into the master page. I'll try using the contentplaceholder method in the head of the master page. I'm sure it will work.

I'm still interested in the questions I posed in the previous post.

Thanks,
John&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=671871" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#668195</link><pubDate>Sun, 15 Oct 2006 16:46:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:668195</guid><dc:creator>John King</dc:creator><author>John King</author><description>Hi:

The code provided by Eric Eubank and Forrest looks very useful. I have to admit that understand of Forrest's version much better than I understand Eric's. 

My main difficulty with Eric's is that I don't understand where to use it. In the case of layered Master Pages, where should this code be placed?

In the following snippet:

(ContentPlaceHolder)Page.Master.FindControl("phContent");

I'm assuming that the argument "phContent" is the id of the ContentPlaceHolder in the Master page that contains control in which you are interested. Is that correct.


As for Forrest's version, I applied it in the content page. To help me understand it, I modified the string to add "&lt;br&gt;" and then wrote the result to the page so I could see the results. (I haven't been successful using this technique with Eric's code, but that may be the result of my misusing it.)

It did what I thought it would do, but my question is how to apply this? By running this, are they set as Javascript global variables so that I can access them whenever I need to in whichever function references them? I'm trying to work out simple test cases, but so far I haven't been successful.

My application, right now, is primarily for custom form validation comparing an email address with a confirm email address value while using master pages. the text box controls are on the content page. Obviously, name mangling makes this a cumbersome task at best. hardcoding the mangled names results in what I want, but obviously that is not what I want to to.

A couple of other questions:

Is there an advantage to doing this for ALL controls in a page, or should I modify this to get the individual control or controls in which I am interested? I can see it both ways. Why walk the entire structure multiple times when you can do it once. Or is it better to simply get what you need when you need it and not keep a bunch of essentially unneeded information around?

Thanks for the contribution to this thread. It has given me something to think about.

John

&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=668195" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#662747</link><pubDate>Sat, 14 Oct 2006 14:36:44 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:662747</guid><dc:creator>ScottGu</dc:creator><author>ScottGu</author><description>&lt;p&gt;Hi Chris,&lt;/p&gt;
&lt;p&gt;You can use class names instead of IDs to name CSS rules. &amp;nbsp;I actually recommend these since they allow you to use them with multiple elements across a site, and also work fine regardless of how deep a control is nested.&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Scott&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=662747" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#661092</link><pubDate>Sat, 14 Oct 2006 02:40:54 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:661092</guid><dc:creator>DK</dc:creator><author>DK</author><description>I am passing the following script to a calendar popup. My intention is to set the selected text to a textbox on a content page. The script changes the bgcolor but it doesn't set the date  and also calendar form doesn't close.
"&lt;script language='javascript'&gt;window.opener.document.bgColor='beige';window.opener.document.bgColor='red';var ctl = window.opener.document.getElementById('ctl00_MainContent_txtDate');ctl.value = '17/10/2006';window.close();&lt;/script&gt;"&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=661092" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#660063</link><pubDate>Fri, 13 Oct 2006 19:49:26 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:660063</guid><dc:creator>Chris</dc:creator><author>Chris</author><description>"Note that ID values are deterministic - so you will get consistent controlID names at runtime."

Very true. But, isn't that deterministic name based on control depth and order? The minute those change, the ids are changed, and your CSS is hosed.

And from a practical standpoint, deterministic still doesn't mean 'sensical for a designer not involved in the programming the project'...

As far as always using classes...that isn't always possible either. Sometimes you need to work around CSS specificity issues where thing need to be applied to a moer specific #id rather than .class.

I'll always be the official bad guy broken record that proclaims master pages and control id futzing bad for separation of code from content.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=660063" width="1" height="1"&gt;</description></item><item><title>re: Great New Advanced Article on ASP.NET 2.0 Master Pages</title><link>http://weblogs.asp.net/scottgu/archive/2006/04/18/Great-New-Advanced-Article-on-ASP.NET-2.0-Master-Pages.aspx#655986</link><pubDate>Thu, 12 Oct 2006 12:33:38 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:655986</guid><dc:creator>Bohemian</dc:creator><author>Bohemian</author><description>I have a masterpage that I am working on with multiple menus and I want to be able to find the ID at runtime, so I can perform some other action, when that particular menu is in use.

Server side how do I get a list of the menu id's at runtime in C# ?

Is there some foreach construct and collection I can enumerate within a masterpage class to obtain all the menu id's ?

Thanks in advance.
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=655986" width="1" height="1"&gt;</description></item></channel></rss>