Solved

Binding a web user control in another ContentPlaceHolder

Posted on 2006-07-18
7
759 Views
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>

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

The ControlID "catSelector" is only found by the compiler if the data source and the CategorySelector are in the same ContentPlaceHolder.
0
Comment
Question by:pallosp
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

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

Bob
0
 
LVL 9

Author Comment

by:pallosp
ID: 17130003
It is a RadioButtonList populated from code. The category ID belonging to the SelectedIndex property is led out as SelectedCategory.
0
 
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?

Bob
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Author Comment

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

masterpage.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"></asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>

default.aspx:

<%@ 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>
<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:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetItems"
        TypeName="Class1">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="prefix" PropertyName="Text" Type="String" />
        </SelectParameters>
        </asp:ObjectDataSource>
</asp:Content>

app_code/class1.cs:

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.
0
 
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.

Bob
0
 
LVL 96

Accepted Solution

by:
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" />

Bob
0
 
LVL 9

Author Comment

by:pallosp
ID: 17133370
Big thanks!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now