<%= variable does not substitute in user control

Discussion in 'ASP .Net' started by Steve Richter, May 6, 2005.

  1. I have a public variable ( "mZipServiceUrl" ) in my code behind class
    that I am able to substitute into the HTML of the .aspx file:

    <span onclick="WindowOpen('<%=mZipServiceUrl%>')"
    style="text-decoration:underline;cursor:hand;color:red;">
    <%=mZipServiceUrl%>
    </span>

    but in the same page, I cant substitute the same variable into a user
    control:

    <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />

    Nothing gets substituted. The variable name shows up in the rendered
    html, as is.

    What are these substitution variables call? I cant find an explanation
    of them in the MSDN site.

    Can variables be substituted in the .aspx file into user controls?

    thanks,

    -Steve
    Steve Richter, May 6, 2005
    #1
    1. Advertising

  2. Generally, you'll want to change the properties/methods of the usercontrol
    instead of inline style.
    The properties/methods you'll likely to try are Attributes, Text(for
    WebControls) and InnerHTML(for HMTLControls)

    And just as a reminder, you can create a <span> control by adding <span
    id="span_1" runat="server"> to the HTML code, the class type generated will
    be HtmlGenericControl and it gives greater flexibility/compatibility over
    the old codes.

    "Steve Richter" <>
    ???????:...
    >I have a public variable ( "mZipServiceUrl" ) in my code behind class
    > that I am able to substitute into the HTML of the .aspx file:
    >
    > <span onclick="WindowOpen('<%=mZipServiceUrl%>')"
    > style="text-decoration:underline;cursor:hand;color:red;">
    > <%=mZipServiceUrl%>
    > </span>
    >
    > but in the same page, I cant substitute the same variable into a user
    > control:
    >
    > <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    >
    > Nothing gets substituted. The variable name shows up in the rendered
    > html, as is.
    >
    > What are these substitution variables call? I cant find an explanation
    > of them in the MSDN site.
    >
    > Can variables be substituted in the .aspx file into user controls?
    >
    > thanks,
    >
    > -Steve
    >
    Lau Lei Cheong, May 6, 2005
    #2
    1. Advertising

  3. Lau Lei Cheong wrote:
    > Generally, you'll want to change the properties/methods of the

    usercontrol
    > instead of inline style.
    > The properties/methods you'll likely to try are Attributes, Text(for
    > WebControls) and InnerHTML(for HMTLControls)


    yeah, I still cant decide what code I want to put in the code behind
    and what goes on the .aspx page. But I dont understand if
    <%=Variable%> is permitted in a user control or not.
    <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />

    I would prefer any property value not in quotes to be treated as a
    substitution variable:
    <ac:AcLinkControl id="link5" Launch="true" Url=mZipServiceUrl
    style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />

    ( not sure how I would handle the sub elements of an attribute like
    style )

    >
    > And just as a reminder, you can create a <span> control by adding

    <span
    > id="span_1" runat="server"> to the HTML code, the class type

    generated will
    > be HtmlGenericControl and it gives greater flexibility/compatibility

    over
    > the old codes.


    thanks for the info. my control is something like a LinkButton, only
    it has some javascript elements to it that allow a new window to be
    launched when the link is clicked.

    -Steve

    >
    > "Steve Richter" <>
    > ???????:...
    > >I have a public variable ( "mZipServiceUrl" ) in my code behind

    class
    > > that I am able to substitute into the HTML of the .aspx file:
    > >
    > > <span onclick="WindowOpen('<%=mZipServiceUrl%>')"
    > > style="text-decoration:underline;cursor:hand;color:red;">
    > > <%=mZipServiceUrl%>
    > > </span>
    > >
    > > but in the same page, I cant substitute the same variable into a

    user
    > > control:
    > >
    > > <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    > > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    > >
    > > Nothing gets substituted. The variable name shows up in the

    rendered
    > > html, as is.
    > >
    > > What are these substitution variables call? I cant find an

    explanation
    > > of them in the MSDN site.
    > >
    > > Can variables be substituted in the .aspx file into user controls?
    > >
    > > thanks,
    > >
    > > -Steve
    > >
    Steve Richter, May 6, 2005
    #3
  4. "Steve Richter" <>
    ???????:...
    > yeah, I still cant decide what code I want to put in the code behind
    > and what goes on the .aspx page. But I dont understand if
    > <%=Variable%> is permitted in a user control or not.
    > <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    >
    > I would prefer any property value not in quotes to be treated as a
    > substitution variable:
    > <ac:AcLinkControl id="link5" Launch="true" Url=mZipServiceUrl
    > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    >
    > ( not sure how I would handle the sub elements of an attribute like
    > style )


    In your ASPX file, add:
    <a id="link5" style="text-decoration:underline;cursor:hand;color:red;"
    runat="server">

    In codebehind, write:(this example in C#)
    link5.Url = "javascript:WindowOpen('" + mZipService + "')";
    link.InnerHtml = mZipService;

    The above should do what your line shown.
    link.Url line can be changed to the following but I've not test to see if it
    works or not...

    link.Attributes.Add("onclick", "WindowOpen('" + mZipService + "')");

    The above should produce exactly the same output if it works.
    Lau Lei Cheong, May 6, 2005
    #4
  5. Oops, after the Attribute.Add() line you have to add link5.Href =
    "javascript:;"; or link5.Href = "#";

    "Lau Lei Cheong" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    > "Steve Richter" <>
    > ???????:...
    >> yeah, I still cant decide what code I want to put in the code behind
    >> and what goes on the .aspx page. But I dont understand if
    >> <%=Variable%> is permitted in a user control or not.
    >> <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    >> style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    >>
    >> I would prefer any property value not in quotes to be treated as a
    >> substitution variable:
    >> <ac:AcLinkControl id="link5" Launch="true" Url=mZipServiceUrl
    >> style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    >>
    >> ( not sure how I would handle the sub elements of an attribute like
    >> style )

    >
    > In your ASPX file, add:
    > <a id="link5" style="text-decoration:underline;cursor:hand;color:red;"
    > runat="server">
    >
    > In codebehind, write:(this example in C#)
    > link5.Url = "javascript:WindowOpen('" + mZipService + "')";
    > link.InnerHtml = mZipService;
    >
    > The above should do what your line shown.
    > link.Url line can be changed to the following but I've not test to see if
    > it works or not...
    >
    > link.Attributes.Add("onclick", "WindowOpen('" + mZipService + "')");
    >
    > The above should produce exactly the same output if it works.
    >
    >
    Lau Lei Cheong, May 6, 2005
    #5
  6. Lau Lei Cheong wrote:
    > "Steve Richter" <>
    > ???????:...
    > > yeah, I still cant decide what code I want to put in the code

    behind
    > > and what goes on the .aspx page. But I dont understand if
    > > <%=Variable%> is permitted in a user control or not.
    > > <ac:AcLinkControl id="link5" Launch=true Url='<%=mZipServiceUrl%>'
    > > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    > >
    > > I would prefer any property value not in quotes to be treated as a
    > > substitution variable:
    > > <ac:AcLinkControl id="link5" Launch="true" Url=mZipServiceUrl
    > > style="color:red; LinkText="<%=mZipServiceUrl%>" runat="server" />
    > >
    > > ( not sure how I would handle the sub elements of an attribute like
    > > style )

    >
    > In your ASPX file, add:
    > <a id="link5"

    style="text-decoration:underline;cursor:hand;color:red;"
    > runat="server">
    >
    > In codebehind, write:(this example in C#)
    > link5.Url = "javascript:WindowOpen('" + mZipService + "')";
    > link.InnerHtml = mZipService;
    >
    > The above should do what your line shown.
    > link.Url line can be changed to the following but I've not test to

    see if it
    > works or not...
    >
    > link.Attributes.Add("onclick", "WindowOpen('" + mZipService + "')");
    >
    > The above should produce exactly the same output if it works.


    ok, thanks.
    Steve Richter, May 6, 2005
    #6
    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. Bengt Richter
    Replies:
    16
    Views:
    546
    Steven D'Aprano
    Jan 21, 2006
  2. Keith G Hicks
    Replies:
    10
    Views:
    517
    Fernando Rodriguez, MCP
    May 1, 2008
  3. Hans
    Replies:
    2
    Views:
    197
  4. MegaC
    Replies:
    3
    Views:
    496
    Brian Helterline
    May 24, 2004
  5. jrough

    substitute a variable with a string

    jrough, May 25, 2011, in forum: Javascript
    Replies:
    2
    Views:
    165
Loading...

Share This Page