views:

63

answers:

1

I am using the below example code and have a problem where I can't pass the Request.RawUrl value into an object that extends the Control object (class Test below).

When I use the line:

<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %>"></Test1:Test>

I find that the Target property is never called.

If I use this line instead:

<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %> test"></Test1:Test>

the string value "<%# Request.RawUrl %> test" is passed to the Target property.

If I use this line as explained in many posts online:

<Test1:Test runat="server" ID="testControl" Target="<%= Request.RawUrl %>"></Test1:Test>

the string value "<%= Request.RawUrl %>" is passed to the Target property.

I need to get the value of Request.RawUrl passed to the Target Property of my Test control object. Does anyone have any ideas where I am going wrong?


Control:

namespace Testing
{
    public class Test : Control
    {
        public Test()
        {

        }

        private string target;

        public string Target
        {
            get { return target; }
            set { target = value; }
        }
    }
}

User Control:

<%@ Control Language="C#" Debug="true" %>
<%@ Register TagPrefix="Test1" Assembly="Test" Namespace="Testing" %>

<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %>"></Test1:Test>
+2  A: 

You need to call testControl.DataBind() in code. <%# gets set when DataBind() is called. <%= is equivalent to Response.Write().

dana