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?
views:
613answers:
2
+1
A:
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.
Gavin Miller
2009-05-06 19:19:57
@LFSR Consulting: Parser Error Message: Server tags cannot contain <% ... %> constructs.
Brian David Berman
2009-05-06 19:21:31
@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
2009-05-06 19:37:13
@Brian, that's my bad, I can never remember which value to use; try: <%# ddlFoo.SelectedValue %>
Gavin Miller
2009-05-06 19:45:21
A:
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;
}
}
DaDa
2009-05-06 19:23:15
I'm trying to pass values from other controls, not hard-coded values.
Brian David Berman
2009-05-06 19:39:46