开发者

Can't pass a variable to a user control

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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜