1

Is there a way pass values from other controls (e.g. "selected value of dropdownlist", "value from query string") to a User Control using a property within the tag itself and NOT from the code behind?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Brian David Berman
  • 7,514
  • 26
  • 77
  • 144

2 Answers2

1

Yes you can, you just need to use the <% %> in the presentation code. Your code would look something like this:

<asp:DropDownList id="ddlFoo" runat="server">
    ...
</asp:DropDownList>
<asp:TextBox id="txtBar" runat="server" Text='<%# ddlFoo.SelectedValue %>' />

<%-- For query string --%>
<asp:TextBox id="txtBar" runat="server" 
    Text='<%# Request.QueryString["Key_Value"] %>' />

The SO post In ASP.Net, what is the difference between <%= and <%# gives a good listing of the different binding mechanisms you can use.

Community
  • 1
  • 1
Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
0

Yes it is. For example

 <uc1:CompetitionClassification ID="CompetitionClassification" runat="server" OnlyTopFive="True" />

in this case, the parameter OnylTopFive is passed within tag of my custom control.

then in server side of my control, i have :

private bool onlyTopFive;
  public bool OnlyTopFive
    {
        get
        {
            return this.onlyTopFive;
        }
        set
        {
            this.onlyTopFive = value;
        }
    }
Iralda Mitro
  • 7,190
  • 5
  • 24
  • 29