How can I change an URL?

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I have this image in my HTML code:
<img src="images/en-US/myImage.jpg" />

I want to change the URL using the value of a Session variable.
<img src="images/ Session("culture") Value /myImage.jpg" />

This is what I did:
<img src='images/<%# Session("culture") %>/myImage.jpg' />

I change the " to ' because when I was using " I got an error.

I also did this to test my Session Value:
OO<% Response.Write(Session("culture")) %>OO

I got "OOen-USOO" which was what I was expecting.

However the image doesn't show up.

Can someone help me?

I don't know what else to do.

Thank You,
Miguel
 
re:
However the image doesn't show up.

Try importing the globalization namespace:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Globalization" %>

and setting Session("culture") to CultureInfo.CurrentCulture.Name :

<%Session("culture") = CultureInfo.CurrentCulture.Name%>

Then, you can retrieve the image name with :
<img src='images/<%=Session("culture")%>/myImage.jpg' />




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
If you use <%= Session("culture") %> instead of <%# Session("culture") %>
you should get your desired results. <%# ... %> is for data binding. You
could also use Page.DataBind() but it may be overkill for your needs.

HTH
 
In fact, you can probably skip the session object altogether.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Globalization" %>

<img src='images/<%=CultureInfo.CurrentCulture.Name%>/myImage.jpg' />

If you are setting the culture in the globalization section of web.config,
that should work even better than setting a session("culture") variable.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Hi Juan and Dave and Everybody else,

Using <%= worked fine.

I do set culture in Web.Config.

However in my page I have a button to change language (change culture).
It is working the following way:
1. Sets default culture in web.config as "en-US" and Session("culture")
as that value.
2. Detects in Global.asax in Session_start if a cookie exist in client.
3. If exists changes threat culture and also Session("culture")

Then I use <%= Session("culture") %> to change URL's, database fields
and other items in my HTML page.

I have some questions about my approach:
1. Should I use threat culture in <%= ... %>?
2. Should I set threat culture in Page_Load in all pages or setting it
only in Session_Start is enough? Well, at least until the language
button is not pressed which runs a function.
3. Is there a way to change the application culture itself? Is it
better?

These are the questions I came up when building this.

I would appreciate some feedback on this.

Thank You,
Miguel
 
Back
Top