Asp.net User Control or Custom control Property doesnt accept inlineasp.net constract <%= %> is ther

Discussion in 'ASP .Net' started by AleXmanFree, Aug 25, 2008.

  1. AleXmanFree

    AleXmanFree Guest

    Hi , I have got problem with passing my inline based value to y user
    control (or custom control, no matter which one I use, I have tried
    both to make sure it doesnt matter) .
    So say I have property called ImagePath and i want to pass my value
    through asp.net specific inline cunstruction:
    <uc:MyControl runat=server id="someId" ImagePath="<%=
    Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/Images/
    ball_.png" />,

    problem that in my property I get value exactly word for word:<%=
    Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/Images/
    ball_.png , but i Should get it like:
    /WebSiteRoot/App_Themes/Green/Images/ball_.png.

    For example if I use simple img html tag i works:
    <img src="<%= Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/
    Images/ball_.png" />
    But if i add runat=server it brokes and i dont see any image coz the
    path of image already messy string with <%= and so on.

    I tried a lot of attributes to my ImagePath that found in web posts to
    let it work (i.e.: [Bindable(true)],[Category("Data")],
    [Browsable(true)] and many more) but no result.



    Please let me know if you can resolve this interesting trick somehow?
     
    AleXmanFree, Aug 25, 2008
    #1
    1. Advertising

  2. AleXmanFree

    HillBilly Guest

    Re: Asp.net User Control or Custom control Property doesnt accept inline asp.net constract <%= %> is there a workaround?

    I was taught to troubleshoot using isolation: test one thing at a time.

    So isolate your expressions you are attempting to bind to the page. I also
    bring to your attention the use of the root path operator (~) so useful to
    resolve paths. I would then isolate the use of Request.ApplicationPath and
    get that part of your path correct.

    Some parts of your path would look like "~/Images/ball_.png" for example and
    I don't even think App_Theme is known to anything but the compiler but I
    could be wrong about that as I don't think we can bind the Theme to the page
    using an expression which may be why using Server controls vs HTML controls
    appears to produce results.

    "AleXmanFree" <> wrote in message
    news:...
    > Hi , I have got problem with passing my inline based value to y user
    > control (or custom control, no matter which one I use, I have tried
    > both to make sure it doesnt matter) .
    > So say I have property called ImagePath and i want to pass my value
    > through asp.net specific inline cunstruction:
    > <uc:MyControl runat=server id="someId" ImagePath="<%=
    > Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/Images/
    > ball_.png" />,
    >
    > problem that in my property I get value exactly word for word:<%=
    > Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/Images/
    > ball_.png , but i Should get it like:
    > /WebSiteRoot/App_Themes/Green/Images/ball_.png.
    >
    > For example if I use simple img html tag i works:
    > <img src="<%= Request.ApplicationPath %>/App_Themes/<%= Page.Theme %>/
    > Images/ball_.png" />
    > But if i add runat=server it brokes and i dont see any image coz the
    > path of image already messy string with <%= and so on.
    >
    > I tried a lot of attributes to my ImagePath that found in web posts to
    > let it work (i.e.: [Bindable(true)],[Category("Data")],
    > [Browsable(true)] and many more) but no result.
    >
    >
    >
    > Please let me know if you can resolve this interesting trick somehow?
     
    HillBilly, Aug 25, 2008
    #2
    1. Advertising

  3. AleXmanFree

    AleXmanFree Guest

    Re: Asp.net User Control or Custom control Property doesnt acceptinline asp.net constract <%= %> is there a workaround?

    Finally I found a good solution for this case.
    Here is very good post of Dave Reed:
    http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx


    The short steps to achieve similar result are:

    1) Create a class which inherits ExpressionBuilder:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.CodeDom;
    using System.Web.Compilation;
    using System.Web.UI;

    namespace Helper.Configurators
    {
    [ExpressionPrefix("InlineCode")]
    public class CodeExpressionBuilder : ExpressionBuilder
    {
    public override CodeExpression GetCodeExpression(BoundPropertyEntry
    entry, object parsedData, ExpressionBuilderContext context)
    {
    return new CodeSnippetExpression(entry.Expression);
    }
    }
    }

    2) register the newly created class in Web.Config:

    <expressionBuilders>
    <add expressionPrefix="InlineCode"
    type="Helper.Configurators.CodeExpressionBuilder"/>
    </expressionBuilders>

    (it must be putted inside <configuration>)

    3) and us it:

    CategoryImage='<%$ InlineCode: Request.ApplicationPath+ "/App_Themes/"
    +Page.Theme+ "/Images/ball_.png" %>'


    Enjoy.
     
    AleXmanFree, Aug 27, 2008
    #3
  4. AleXmanFree

    Hillbilly Guest

    Re: Asp.net User Control or Custom control Property doesnt accept inline asp.net constract <%= %> is there a workaround?

    I really appreciate your commitment to come back to put this news article
    into perspective. I needed more insight into the use of the
    ExpressionBuilder class myself. Thanks again...

    "AleXmanFree" <> wrote in message
    news:...
    > Finally I found a good solution for this case.
    > Here is very good post of Dave Reed:
    > http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
    >
    >
    > The short steps to achieve similar result are:
    >
    > 1) Create a class which inherits ExpressionBuilder:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Text;
    > using System.CodeDom;
    > using System.Web.Compilation;
    > using System.Web.UI;
    >
    > namespace Helper.Configurators
    > {
    > [ExpressionPrefix("InlineCode")]
    > public class CodeExpressionBuilder : ExpressionBuilder
    > {
    > public override CodeExpression GetCodeExpression(BoundPropertyEntry
    > entry, object parsedData, ExpressionBuilderContext context)
    > {
    > return new CodeSnippetExpression(entry.Expression);
    > }
    > }
    > }
    >
    > 2) register the newly created class in Web.Config:
    >
    > <expressionBuilders>
    > <add expressionPrefix="InlineCode"
    > type="Helper.Configurators.CodeExpressionBuilder"/>
    > </expressionBuilders>
    >
    > (it must be putted inside <configuration>)
    >
    > 3) and us it:
    >
    > CategoryImage='<%$ InlineCode: Request.ApplicationPath+ "/App_Themes/"
    > +Page.Theme+ "/Images/ball_.png" %>'
    >
    >
    > Enjoy.
     
    Hillbilly, Oct 9, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Garg Pankaj

    HtmlInputFile accept property

    Garg Pankaj, Aug 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,412
    bruce barker
    Aug 26, 2003
  2. Vinod I
    Replies:
    1
    Views:
    380
    Brian K. Williams
    Feb 26, 2004
  3. mortb
    Replies:
    2
    Views:
    430
    Peter Blum
    May 10, 2004
  4. Wazza
    Replies:
    4
    Views:
    690
    Roedy Green
    Dec 6, 2007
  5. Replies:
    3
    Views:
    437
    alex23
    May 27, 2008
Loading...

Share This Page