<%= _s_Variable %> not working

J

Jennifer Mathews

I have all my images in a directory called "images/Red". They are all the same color and
look the same way. They are all called like the following code:


<asp:ImageButton ID="cmdSave" runat="server" ImageUrl="~/images/Red/Save.jpg"
AlternateText="Save" />


Now some users are complaining they can't see them clearly but some users want them to
stay that color (Red). No problem I thought. I created Blue buttons and put them in
another directory called "images/Blue".


I have _s_CSS_Btn_DWhr as a friend variable "Red". (The default.) I thought the
following would work in the ascx but it doesn't.


<asp:ImageButton ID="cmdSave" runat="server" ImageUrl="~/images/<%= _s_CSS_Btn_DWhr
%>/Save.jpg" AlternateText="Save" />

Instead of substitues "Red" for <%= _s_CSS_Btn_DWhr %> the processor writes
%3C%25=%20_s_CSS_Btn_DWhr%20%25%3E


Can someone tell me what I am doing wrong?

Thanks
 
G

Guest

I have all my images in a directory called "images/Red". They are all the same color and
look the same way.  They are all called like the following code:

<asp:ImageButton ID="cmdSave" runat="server" ImageUrl="~/images/Red/Save.jpg"
AlternateText="Save" />

Now some users are complaining they can't see them clearly but some users want them to
stay that color (Red).  No problem I thought.  I created Blue buttons and put them in
another directory called "images/Blue".

I have _s_CSS_Btn_DWhr as a friend variable "Red". (The default.)  I thought the
following would work in the ascx but it doesn't.

<asp:ImageButton ID="cmdSave" runat="server" ImageUrl="~/images/<%= _s_CSS_Btn_DWhr
%>/Save.jpg" AlternateText="Save" />

Instead of substitues "Red" for <%= _s_CSS_Btn_DWhr %> the processor writes
%3C%25=%20_s_CSS_Btn_DWhr%20%25%3E

Can someone tell me what I am doing wrong?

Thanks

Try

<asp:ImageButton ID="cmdSave" runat="server" ImageUrl="<%= "~/images/"
& _s_CSS_Btn_DWhr & "/Save.jpg" %>" AlternateText="Save" />

if it's on c# then use + instead of &
 
A

Andrew Morton

Jennifer said:
Can someone tell me what I am doing wrong?

Using <% %> inside a control won't necessarily work. Instead, you can set
cmdSave.ImageUrl in the Page_Load handler.

Andrew
 
G

Guest

Using <% %> inside a control won't necessarily work. Instead, you can set
cmdSave.ImageUrl in the Page_Load handler.

Andrew

Andrew, you're right, please ignore my post...

Jennifer, either assign url in the code behind, or add in top of your
page

<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
cmdSave.ImageUrl = "~/images/" & _s_CSS_Btn_DWhr & "/
Save.jpg"
End Sub
</script>

and then it should work.
 
J

Jennifer Mathews

Wow. I have to change probably a couple of hundred of these and doing this in the code
behind really is terrible. I was really hoping I could do this with a search & replace
for all the ascx pages. Of well. Thanks for the replies.
 
G

Guest

Wow.  I have to change probably a couple of hundred of these and doing this in the code
behind really is terrible.  I was really hoping I could do this with a search & replace
for all the ascx pages.  Of well.  Thanks for the replies.








- Show quoted text -

Another option could be converting ASP.NET control into HTML input
control

<input type="image" src='<%"/images/" & _s_CSS_Btn_DWhr & "/Save.jpg"
%>' />

which could act the same as ImageButton
 
A

Andrew Morton

Jennifer said:
Wow. I have to change probably a couple of hundred of these and
doing this in the code behind really is terrible. I was really
hoping I could do this with a search & replace for all the ascx
pages. Of well. Thanks for the replies.

You could write a program to do it...

Andrew
 
J

Jennifer Mathews

Actually, I just had to use the hyperlink HTML control (non ASP.Net one) to get around a
problem. 99% of the time MS out-thinks us in a good way. But in that 1% of the time,
what a pain-in-the-neck programming can be.

I am going to play with this idea. There might be some problems with this because there
is quite a bit of onClientClick stuff in there.

Thanks again to everyone.


Wow. I have to change probably a couple of hundred of these and doing this in the code
behind really is terrible. I was really hoping I could do this with a search & replace
for all the ascx pages. Of well. Thanks for the replies.








- Show quoted text -

Another option could be converting ASP.NET control into HTML input
control

<input type="image" src='<%"/images/" & _s_CSS_Btn_DWhr & "/Save.jpg"
%>' />

which could act the same as ImageButton
 
G

Guest

Actually, I just had to use the hyperlink HTML control (non ASP.Net one) to get around a
problem.  99% of the time MS out-thinks us in a good way.  But in that 1% of the time,
what a pain-in-the-neck programming can be.

I am going to play with this idea.  There might be some problems with this because there
is quite a bit of onClientClick stuff in there.

Thanks again to everyone.






Another option could be converting ASP.NET control into HTML input
control

<input type="image" src='<%"/images/" & _s_CSS_Btn_DWhr & "/Save.jpg"
%>'   />

which could act the same as ImageButton- Hide quoted text -

- Show quoted text -

What you can also do is to try to use themes and skins. Because
personalization is exactly what they were designed for.
http://msdn.microsoft.com/de-de/library/wcyt4fxb(VS.80).aspx
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top