This topic is locked
[SOLVED]

 Language selector on page with no menu

9/23/2020 5:56:41 AM
ASPRunner.NET General questions
Pete K author

I have a very simplified app with no welcome screen and only add and view pages. There is no login. But I need to support multiple languages. How can I get the language selector that normally appears on the login and menu to appear on the add screen? Or how can I replicate it in code?

Pete K author 9/24/2020

I submitted a support request and as usual, Sergey came to the rescue. He pointed me to this article for inserting a DDL that pulls info from a table to display options and uses Javascript to submit the page on user change:

https://nam11.safeli...&reserved=0
I re-wrote the server code in c# and modified it to pull from a table I set up to list the languages in use. Adding the querystring "language=Spanish" (or whatever) to the URL does all the magic. I could have hard-coded the language options as well. Here's my code:



string str = "<select style='width: 150px; display: inline-block;' class='form-control' onchange=\"window.location.href=this.options[this.selectedIndex].value;\"><option value=\"\">Change language</option>";

//select values from the database

string strSQL = "select Language, DisplayLang from _lang";

dynamic data;

dynamic rs = DB.Query(strSQL);

while (data = rs.fetchAssoc())

{

str += "<option value='contactrequests/add?language=" + data["Language"].ToString()+ "'>" + data["DisplayLang"].ToString() + "</option>";

}

str += "</select>";

MVCFunctions.Echo(str);


Something else I discovered: once you add language to a querystring once, the ASPR framework apparently sets a language session variable so subsequent pages don't need to repeat the querystring. Smart!