Getting a url parameter into asp.net label

asp.net

I am trying to automatically set the text of a asp:label to a url parameter but it does not seem to work.

This is the code I have:

     <asp:Label ID="lblHouse" runat="server" 
        Text='<%# Request.QueryString["Selection"] %>' 
        Font-Bold="True" 
        Font-Size="Large"></asp:Label> <br /> <br />

What am I doing wrong?

Thanks for your help.

Best Solution

You can use <%= %> (instead of <%#) and put it inside of the asp:label tag, instead of the Text property:

            <asp:Label ID="lblHouse" runat="server"  
            Font-Bold="True"  
            Font-Size="Large"><%= Server.HTMLEncode(Request.QueryString["Selection"]) %></asp:Label>
Related Question