#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Location
    Detroit area, MI
    Posts
    5
    Rep Power
    0

    Exclamation Multilingual website, need to add querystrings at the end of URLs


    I am not a programmer, but I have a multilingual company website (Visual Studio / VB / ASP.NET 4.0), and when, on the homepage, you click a flag, the text changes to that language and stays with you the entire session, after I made a class, BasePage.vb. Everything works great, but the URL never changes .... clients.aspx remains clients.aspx although the text DOES switch to Dutch.

    It's been recommended by @Aritstos to make it so it looks like clients.aspx?lang=nl as opposed to just clients.aspx in Dutch.

    Currently, my asp homepage hyperlinks that work look like this:

    Code:
          <asp:LinkButton ID="LinkButton7" runat="server"
          CommandArgument="nl" OnClick="RequestLanguageChange_Click"
          class="flagbutton">      
          <asp:Image ID="Image1" runat="server" ImageUrl="~/images/flagnl.png"
          tooltip="Bekijk deze website in het Nederlands" title="Bekijk deze website 
          in het Nederlands"/>
          <img class="map" src="images/flaghovernl.png" alt=""/>
          </asp:LinkButton>
    I tried to change the asp links to html links, like this:

    Code:
         <a href="default.aspx?lang-nl" class="flagbutton">
         <img src="images/flagnl.png" alt="Bekijk deze website in het Nederlands"
         title="Bekijk deze website in het Nederlands"/>
         <img class="map" src="images/flaghovernl.png" alt=""/>
    But that didn't work. The page doesn't switch languages to Dutch. And when I click on any link, say, about.aspx, the ?lang-nl disappears. I think it's because I took the CommandArgument out. So nothing appears in Dutch. I was told the asplinks do the javascript_dopostback which is bad. Can somebody please tell me how to change my links so that they create a string at the end of the URL saying "?lang-nl" at the end, and it stays like that through their entire session? Any help would be sincerely appreciated!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Location
    Charlotte
    Posts
    412
    Rep Power
    144
    Originally Posted by jasonpaulweber
    I am not a programmer, but I have a multilingual company website (Visual Studio / VB / ASP.NET 4.0), and when, on the homepage, you click a flag, the text changes to that language and stays with you the entire session, after I made a class, BasePage.vb. Everything works great, but the URL never changes .... clients.aspx remains clients.aspx although the text DOES switch to Dutch.

    It's been recommended by @Aritstos to make it so it looks like clients.aspx?lang=nl as opposed to just clients.aspx in Dutch.

    Currently, my asp homepage hyperlinks that work look like this:

    Code:
          <asp:LinkButton ID="LinkButton7" runat="server"
          CommandArgument="nl" OnClick="RequestLanguageChange_Click"
          class="flagbutton">      
          <asp:Image ID="Image1" runat="server" ImageUrl="~/images/flagnl.png"
          tooltip="Bekijk deze website in het Nederlands" title="Bekijk deze website 
          in het Nederlands"/>
          <img class="map" src="images/flaghovernl.png" alt=""/>
          </asp:LinkButton>
    I tried to change the asp links to html links, like this:

    Code:
         <a href="default.aspx?lang-nl" class="flagbutton">
         <img src="images/flagnl.png" alt="Bekijk deze website in het Nederlands"
         title="Bekijk deze website in het Nederlands"/>
         <img class="map" src="images/flaghovernl.png" alt=""/>
    But that didn't work. The page doesn't switch languages to Dutch. And when I click on any link, say, about.aspx, the ?lang-nl disappears. I think it's because I took the CommandArgument out. So nothing appears in Dutch. I was told the asplinks do the javascript_dopostback which is bad. Can somebody please tell me how to change my links so that they create a string at the end of the URL saying "?lang-nl" at the end, and it stays like that through their entire session? Any help would be sincerely appreciated!
    You're going to have pre-process every new page as it loads, and ADD that querystring to each URL.

    It might be easiest to do this using javascript, possibly jQuery. You could do a FIND on all link elements, and modify that link element to add the desired query string.

    Not sure which version of .NET you're using, but the latest verson you can add jQuery easily. You can do it in older versions, but it's a manual install.

    In jQuery:

    Code:
    $(document).ready(function(){
           
             // write a loop using document.find on each element.  
             // not sure if you can just look for elements of a certain type
             // or if you can see if the type is a "Link"
             // but you should then be able to modify the value to add your query string
    )};

    That
    $(document).ready(function()
    line basically "launches" once the page is ready to be displayed. You can make changes and then the page loads/displays completely. You could modify each link to have the query string.

    As a test, do this:

    Code:
    $(document).ready(function(){
        alert("Page just loaded");
    )};
    You should get a javascript popup each time you hit REFRESH.

    You could write a javascript function that was driven from a button click to test develop code that will iteratively find each html element in that document. Boom, you're done.

    I'm not going to take the time to do all that for you, but that should be enough to get you started.

    If you use FireFox, and use FireBug, you can easily debug (step through) javascript. I've not done that using IE.
    Last edited by Ronster; February 1st, 2012 at 10:58 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Location
    Charlotte
    Posts
    412
    Rep Power
    144
    And you can probably do it in .net also, in the Page_Load() function. I would imagine there is a way to do that.

    Here:
    http://stackoverflow.com/questions/186918/c-sharp-how-to-change-html-elements-attributes

    is somebody asking how to modify html attributes (the URL is an attribute of the LINK element).

    You'd have to be careful though, because if you have links you DIDN'T want modified (say to an external website), it would also decorate them.

IMN logo majestic logo threadwatch logo seochat tools logo