<%= _s_Variable %> not working

  • Thread starter Thread starter Jennifer Mathews
  • Start date Start date
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
 
I have all my images in a directory called "images/Red". They are all thesame 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 userswant them to
stay that color (Red).  No problem I thought.  I created Blue buttonsand 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 &
 
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
 
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.
 
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.
 
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
 
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
 
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
 
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
 
Back
Top