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?
Asked
Active
Viewed 1,459 times
2 Answers
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
-
@LFSR Consulting: Parser Error Message: Server tags cannot contain <% ... %> constructs. – Brian David Berman May 06 '09 at 19:21
-
@LRSR Consulting: I tried your example and it sticks <%= ddlFoo.SelectedValue %> into the textbox as the value (as if it's just a string) – Brian David Berman May 06 '09 at 19:37
-
@Brian, that's my bad, I can never remember which value to use; try: <%# ddlFoo.SelectedValue %> – Gavin Miller May 06 '09 at 19:45
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
-
I'm trying to pass values from other controls, not hard-coded values. – Brian David Berman May 06 '09 at 19:39