Binding a web user control in another ContentPlaceHolder

Posted on 2006-07-18
Last Modified: 2008-01-09
I have a master page with multiple ContentPlaceHolders. The first one contains a web user control of class Controls_CategorySelector. The second one contains a data source, and one of its parameters is bound to the SelectedCategory property of the CategorySelector. How can this binding be done without compilation error?

<asp:Content ID="Content1" ContentPlaceHolderID="LeftMenuHolder" runat="Server">
    <uc1:CategorySelector ID="catSelector" runat="server" OnLoad="CategorySelectorLoad"/>    

<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" runat="Server">
    <asp:SqlDataSource ID="ArticleDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:RTFMConnectionString %>"
        SelectCommand="listRecentArticles" SelectCommandType="StoredProcedure">
            <asp:ControlParameter ControlID="catSelector" DefaultValue="0" Name="categoryId"
                PropertyName="SelectedCategory" Type="Int32" />

The ControlID "catSelector" is only found by the compiler if the data source and the CategorySelector are in the same ContentPlaceHolder.
Question by:pallosp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 96

Expert Comment

by:Bob Learned
ID: 17129733
What is 'CategorySelector' defined as?


Author Comment

ID: 17130003
It is a RadioButtonList populated from code. The category ID belonging to the SelectedIndex property is led out as SelectedCategory.
LVL 96

Expert Comment

by:Bob Learned
ID: 17131211
I was trying to figure out what uc1:CategorySelector was, and it doesn't sound like a RadioButtonList.  Is it a third-party control, or a home-grown custom web control?

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 17132459
Here is a simple code without web user controls that produce the same phenomenon:


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"></asp:ContentPlaceHolder>


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetItems"
            <asp:ControlParameter ControlID="TextBox1" Name="prefix" PropertyName="Text" Type="String" />


public class Class1
    public static string[] GetItems(string prefix) {
        return new string[] { prefix+"1", prefix+"2" };

After TextBox1 had been moved to the first ContentPlaceHolder, the code didn't compile.
LVL 96

Expert Comment

by:Bob Learned
ID: 17132939
It compiled for me with TextBox1 under Context1.  I created a Web Site model type web site, and I don't know which type you created.  But, I can't see where that would cause a problem.

LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 17132978
Aaah, yes, it's a run-time exception:

    Could not find control 'TextBox1' in ControlParameter 'prefix'.

Try this:

            <asp:ControlParameter ControlID="ContentPlaceHolder1$TextBox1" Name="prefix" PropertyName="Text" Type="String" />


Author Comment

ID: 17133370
Big thanks!

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question