Ah! Now I remember. I looked at ClientID before.
"Steven Cheng[MSFT]" wrote:
> Hello Joe,
>
> Regarding on the Master page, since it is acting like a
> template(usercontrol), it will need to divide the page into different
> sections and each sections will be a Namingcontainer so that the controls
> inside that section will has its own Naming convention. This naming
> convention is very important for ASP.NET control structure and event
> handling system to work well(correctly identitfy each control in diffferent
> control hierarchy).
>
> For your scenario, if you have javascript which want to reference some
> nested controls in master page, you can consider the following approach:
>
> In server-side code, use Control.ClientID property to get the ID it will be
> rendered to client-side(represent its client-side id that can be used by
> javascript). You actually use Page.ClientScript to register some javascript
> functions to return these ClientIDs and use them by other scripts. e.g.
>
> #register those functions that return the correct client id of those
> controls
> =========================
> public partial class ContentPage1 : System.Web.UI.Page
> {
> .............................
>
> protected void Page_PreRender(object sender, EventArgs e)
> {
> string script = "\r\nfunction get_TextBox1_id(){return '" +
> TextBox1.ClientID + "';}";
>
> script += "\r\nfunction get_TextBox2_id(){return '" +
> TextBox2.ClientID + "';}";
>
> script += "\r\nfunction get_Button1_id(){return '" +
> Button1.ClientID + "';}";
>
>
> Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
> "id_script", script, true);
>
> }
> }
>
>
>
> #you can use these functions in page's other scripts(either defined in
> master page or in content page)
> =======================================
>
> function test_client_id()
> {
> alert(document.getElementById(get_TextBox1_id()));
> alert(document.getElementById(get_TextBox2_id()));
> alert(document.getElementById(get_Button1_id()));
>
> }
> ==================
>
> Hope this helps you.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
> ==================================================
>
> Get notification to my posts through email? Please refer to
>
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications.
>
>
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
>
http://msdn.microsoft.com/subscriptions/support/default.aspx. >
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>