<%= variable does not substitute in user control

S

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
 
L

Lau Lei Cheong

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.
 
S

Steve Richter

Lau said:
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
 
L

Lau Lei Cheong

Steve Richter said:
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.
 
L

Lau Lei Cheong

Oops, after the Attribute.Add() line you have to add link5.Href =
"javascript:;"; or link5.Href = "#";
 
S

Steve Richter

Lau said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top