user.Roles.FirstOrDefault() returns DynamicProxy - asp.net

OK...
I was finally making some headway with creating a User Management page using Identity 2 in Web Forms.
It was mostly moving along just fine. When suddenly I run into this issue, and it makes no sense to me.
I have an AS form with a dropdown list of Roles. That list is populated using
roleMgr.Roles.ToList();
Works Great
I use the user being edited Role to set the current selected value.
ddlUserType.SelectedValue = user.Roles.FirstOrDefault().ToString();
This WAS working like dynamite
Last week...
Now all of a sudden user.Roles.FirstOrDefault().ToString(); is returning
"System.Data.Entity.DynamicProxies.IdentityUserRole_FDDE5D267CF62D86904A3BC925D70DC410F12D5BE8313308EC89AC8537DC6375"
What he heck, man?
So I tried user.Roles.Take(1).ToString();
That returns
"System.Linq.Enumerable+d__24`1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole]"
I have to presume I Broke, Something...
But What?
Nothing in this code page changed at all between when it worked and then didn't.
The only thing I did related to Identity at all was Migrate a couple of fields into AspNetUsers (another whole ballgame, migrations...) which also worked like dynamite BTW.
I even went to the extreme of wiping out my Migrations and AspNet user tables entirely, and re-initializing it all.
Any suggestions ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Sperry_Parts.Models;
using Sperry_Parts.Logic;
using Microsoft.AspNet.Identity.Owin;
using Owin;
namespace Parts.Admin
{
public partial class CreateEditUser : System.Web.UI.Page
{
private bool NewUser
{
get { return ViewState["NewUser"] != null ? (bool)ViewState["NewUser"] : false; }
set { ViewState["NewUser"] = value; }
}
private string EditUser
{
get { return (string)ViewState["EditUser"]; }
set { ViewState["EditUser"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
EditUser = Session["Edit_User"].ToString();
// Access the application context and create result variables.
Models.ApplicationDbContext context = new ApplicationDbContext();
RoleActions roleAction = new RoleActions();
// Create a RoleStore object by using the ApplicationDbContext object.
var roleStore = new RoleStore<IdentityRole>(context);
// Create a RoleManager object that is only allowed to contain IdentityRole objects.
var roleMgr = new RoleManager<IdentityRole>(roleStore);
// Load the DDL of Roles
var roles = roleMgr.Roles.ToList();
ddlUserType.DataTextField = "Name";
ddlUserType.DataValueField = "Id";
ddlUserType.DataSource = roles;
ddlUserType.DataBind();
if (EditUser == "")
{
txtUserName.Enabled = true;
txtUserName.Focus();
NewUser = true;
} // End New User
else
{
// User part
var userMgr = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
txtUserName.Enabled = false;
txtFullName.Focus();
var user = userMgr.FindByName(EditUser);
if (user != null)
{
txtUserName.Text = user.UserName;
txtUserEmail.Text = user.Email;
txtFullName.Text = user.FullName;
var hisroles = user.Roles.ToList(); // properly returns 1 item
// this is where it went off the rails - these 4 lines are debugging code
string xrole = user.Roles.FirstOrDefault().ToString();
string role2 = user.Roles.Take(1).ToString();
string trythis = xrole.ToString();
string trythis2 = role2.ToString();
// I swear, this worked last week...
ddlUserType.SelectedValue = user.Roles.FirstOrDefault().ToString();
}
} // End Editing User
} // End if (!IsPostBack)
} // End Page Load
protected void CreateUser()
{
// removed as non-relevant to question
} // End CreateUser
protected void UpdateUser()
{
// removed as non-relevant to question
} // End UpdateUser
protected void btnSave_Click(object sender, EventArgs e)
{
// removed as non-relevant to question
} // End btnSave
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/ManageUsers");
} // End btnCancel
} // End Class CreateEditUser
}

I ran into the same problem trying to set the value of a "Roles" DropDownList inside a GridView Control. I solved it by using:
user.Roles.First().RoleId
It just happens that my RoleId is also my role name.

Related

Xamarin.Forms page is not appearing immediately after another page has been popped

I have three pages at the moment in my app. I will call them EventsPage, NewEventPage, and ListPage. EventsPage is the first page of the app and you can open a NewEventPage from there. On this NewEventPage is a button that pops the NewEventPage from the stack and is supposed to create a ListPage immediately afterward, but the ListPage is not appearing, although I found out that its constructor is running.
Here's the code for the NewEventPage:
using Partylist.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Partylist.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NewEventPage : ContentPage
{
// Constructor.
public NewEventPage()
{
InitializeComponent();
}
// Event handlr for when the "Cancel" button is clicked.
async void OnCancelClicked(object sender, EventArgs e)
{
// Goes back to the previous page.
await Navigation.PopAsync();
}
// Event handler for when the "Create" button gets clicked.
async void OnCreateClicked(object sender, EventArgs e)
{
// Make sure there is something in the text entry.
if (string.IsNullOrWhiteSpace(EventNameEntry.Text))
{
// If there is nothing there, print an error message.
ErrorLabel.Text = "Your event needs a name!";
}
// If there is something in the text entry, try to create
// a new event with the text as its name.
else
{
// Variable to store the created event.
Event newEvent = new Event();
// Variable to store its folder.
DirectoryInfo newEventFolder;
// Flag to see if the event was created sccessfully.
bool eventCreated;
try
{
// If there's already an event with that name, let the
// user know.
if
(Directory.Exists(Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
EventNameEntry.Text)))
{
ErrorLabel.Text = "You already have an event with that name.";
eventCreated = false;
}
// Otherwise, try to creaate the folder.
else
{
newEventFolder = Directory.CreateDirectory(
Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
EventNameEntry.Text));
// Then, create the event based on that folder.
newEvent = new Event
{
FolderName = EventNameEntry.Text,
DateCreated = newEventFolder.CreationTime,
DateEdited = newEventFolder.LastWriteTime
};
// Get rid of any error messages that might be on screen.
ErrorLabel.Text = "";
eventCreated = true;
}
}
// Should throw an ArgumentException in most cases where there is
// an invalid character.
catch (ArgumentException)
{
// Get all the invalid characters and turn them into a string.
char[] invalidChars = Path.GetInvalidPathChars();
string invalid = "";
foreach(char currentChar in invalidChars)
{
invalid += currentChar;
}
// Change the text of the error label.
ErrorLabel.Text = "Your event name can't have these characters: \""
+ invalid + "\".";
eventCreated = false;
}
// If the event was created successfully, select it, pop the "New Event"
// page, and open a "List" page for the event.
if (eventCreated)
{
App.selectedEvent = newEvent;
await Navigation.PopAsync();
await Navigation.PushAsync(new ListsPage());
}
}
}
}
}
And here's the code for the ListPage:
using Partylist.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Partylist.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListsPage : ContentPage
{
// List of lists, used to populate
// the page's ListView (see the XAML).
public ObservableCollection<PartylistList> ListList { get; set; }
// Constructor.
public ListsPage()
{
// Does all the stuff to make the page
// exist that doesn't involve anything
// specific to this particular page in
// this particular app.
InitializeComponent();
}
// Override for OnAppearing().
protected override void OnAppearing()
{
// Regular OnAppearing() method.
base.OnAppearing();
// Set the title to be the name of the selected event.
Title = App.selectedEvent.FolderName;
// Set the BindingContext of the page to itself.
this.BindingContext = this;
// Set the ItemsSource of the ListView in the
// XAML to the ObservableCollection.
ListList = new ObservableCollection<PartylistList>();
ListListView.ItemsSource = ListList;
// Loop to populate the ObservableCollection.
for (int i = 0; i < Directory.GetFiles(
Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
App.selectedEvent.FolderName))
.Length; i++)
{
// Add a new list.
ListList.Add(new ContactList());
// Set the filename to the name of the file
// that the list corresponds to.
ListList.ElementAt(i).Filename =
Directory.GetFiles(
Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
App.selectedEvent.FolderName))[i];
// Sets the date/time created to the file's
// creation date.
ListList.ElementAt(i).DateCreated = Directory
.GetCreationTime(Directory.GetFiles(
Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
App.selectedEvent.FolderName))[i]);
// Sets the date/time last edited to the
// folder's write date.
ListList.ElementAt(i).DateEdited = Directory
.GetLastWriteTime(Directory.GetFiles(
Path.Combine(Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData),
App.selectedEvent.FolderName))[i]);
}
}
}
}

Adding Xamarin app a searchbar

I made a simple Xamarin Cross platform SQLite app which can inserts, updates, deletes data from a listview. I want to add a searchbar. Following this tutorial i added this on my HomePage.xaml
Now if my listview's source was a list just like in the tutorial i had to write this in HomePage.xaml.cs
private void mySearchBar_ButtonPressed(object sender, EventArgs e)
{
string searchText = mySearchBar.Text;
myListView.ItemsSource=ListViewsListSource.Where(name=>name.Contains(searchText ));
}
But i defined my listview's source like this.
using (var dataaccess= new DataAccess())
{
listaListView.ItemsSource = dataaccess.GetEmployers();
}
And GetEmployers is defined in DataAccess
public List<Employer> GetEmployers()
{
return connection.Table<Employer>().OrderBy(c => c.Lastname).ToList();
}
Now what should i write in mySearchBar_ButtonPressed ?
There are a lot of different ways to approach this. Following your own example, you could add a Search method to your DataAccess class
public List<Employer> SearchEmployers(string key)
{
return connection.Table<Employer>().Where(e => e.Lastname.Contains(key) || e.FirstName.Contains(key)).OrderBy(c => c.Lastname).ToList();
}
private void mySearchBar_ButtonPressed(object sender, EventArgs e)
{
string searchText = mySearchBar.Text;
listaListView.ItemsSource = dataaccess.SearchEmployers(searchText);
}

ProfileCommon could be not found

I got error ProfileCommon could be not found , in my code. I don't know how to fix the error. I put namespace using system.Web.Profile, but error still does here. Could someone help how to do that? Please help me if you know. Thank you
public partial class UserProfile : System.Web.UI.UserControl
{
private string _userName = "";
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
protected void Page_Init(object sender, EventArgs e)
{
this.Page.RegisterRequiresControlState(this);
}
protected override void LoadControlState(object savedState)
{
object[] ctlState = (object[])savedState;
base.LoadControlState(ctlState[0]);
_userName = (string)ctlState[1];
}
protected override object SaveControlState()
{
object[] ctlState = new object[2];
ctlState[0] = base.SaveControlState();
ctlState[1] = _userName;
return ctlState;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// if the UserName property contains an emtpy string, retrieve the profile
// for the current user, otherwise for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
txtFirstName.Text = profile.FirstName;
txtLastName.Text = profile.LastName;
ddlGenders.SelectedValue = profile.Gender;
if (profile.BirthDate != DateTime.MinValue)
txtBirthDate.Text = profile.BirthDate.ToShortDateString();
ddlOccupations.SelectedValue = profile.Occupation;
txtWebsite.Text = profile.Website;
txtStreet.Text = profile.Address.Street;
txtCity.Text = profile.Address.City;
txtPostalCode.Text = profile.Address.PostalCode;
txtState.Text = profile.Address.State;
txtPhone.Text = profile.Contacts.Phone;
txtFax.Text = profile.Contacts.Fax;
}
}
public void Save()
{
// if the UserName property contains an emtpy string, save the current user's
// profile, othwerwise save the profile for the specified user
ProfileCommon profile = this.Profile;
if (this.UserName.Length > 0)
profile = this.Profile.GetProfile(this.UserName);
profile.FirstName = txtFirstName.Text;
profile.LastName = txtLastName.Text;
profile.Gender = ddlGenders.SelectedValue;
if (txtBirthDate.Text.Trim().Length > 0)
profile.BirthDate = DateTime.Parse(txtBirthDate.Text);
profile.Occupation = ddlOccupations.SelectedValue;
profile.Website = txtWebsite.Text;
profile.Address.Street = txtStreet.Text;
profile.Address.City = txtCity.Text;
profile.Address.PostalCode = txtPostalCode.Text;
profile.Address.State = txtState.Text;
profile.Contacts.Phone = txtPhone.Text;
profile.Contacts.Fax = txtFax.Text;
profile.Save();
}
}
As Mark pointed out, profiles only work out-of-the-box with the website template and I have blogged instructions on how to use the plug-in to facilitate the use of profiles for the Web Application project:
http://www.codersbarn.com/post/2008/07/10/ASPNET-PayPal-Subscriptions-IPN.aspx
It is possible to do it yourself, and here's a fully working implementation that you can download:
http://leedumond.com/blog/asp-net-profiles-in-web-application-projects/
According to these links(link1, link2)
Web Applications don't support the auto generation of the ProfileCommon object
The first link then give's a link to a VS Addin and instructions on how to incorporate it into the build process in order to work around the problem
There is a very simple work-around for this, for all coders who just want to hack on with things. You can get the ProfileBase type and load the profile into that, but you lose strong typing. If you are in control of the data in the profile, or you are sure that the data in the profile is of a certain type, you are good to go.
string user = "Steve"; // The username you are trying to get the profile for.
bool isAuthenticated = false;
MembershipUser mu = Membership.GetUser(user);
if (mu != null)
{
// User exists - Try to load profile
ProfileBase pb = ProfileBase.Create(user, isAuthenticated);
if (pb != null)
{
// Profile loaded - Try to access profile data element.
// ProfileBase stores data as objects in (I assume) a Dictionary
// so you have to cast and check that the cast succeeds.
string myData = (string)pb["MyKey"];
if (!string.IsNullOrWhiteSpace(myData))
{
// Woo-hoo - We're in data city, baby!
Console.WriteLine("Is this your card? " + myData + " - Ta Dah!");
}
}
}

How to implement Generics in business object class definition with DAL to create a proper user control dropdown

I am woefully new to generics, being tied to the support of a corporate intranet web application whose upgrade process is bound to red tape and slowwwly-changing standards. Consequently, today (thankfully!) I finally find myself scrambling during our upgrade to .Net 3.5 and transitioning all the code I can to a properly tiered model.
I have been reading all morning about generics trying to digest how to transition dropdown user controls into a proper business object that gets its data from a class in the data access layer.
There is a perfectly succinct question here that details exactly what I am interested in exploring: Set selected index in a Dropdownlist in usercontrol.
What I would love to see, however, is what Travel_CarSizes.GetCarSizes() actually looks like inside and how the class Travel_CarSizes is defined. (I am having a hard time with <T> and knowing where it should occur.)
For my own specific circumstance at the moment I need a dropdown user control to contain location directionals (N, S, W, C/O, NW, SE, etc) that are stored in a SQL table in the DB and whose selected index needs to be able to be set by whichever page it happens to be in, when form data exists.
I have begun to implement the model in the example from the link above but right now without using Generics because I can't figure it out:
The dropdown user control:
public partial class DropDownStreetPrefix : System.Web.UI.UserControl
{
public string StreetPrefixValue
{
get { return ddlStreetPrefix.SelectedValue.ToString(); }
set
{
Bind();
ddlStreetPrefix.SelectedIndex = ddlStreetPrefix.Items.IndexOf(ddlStreetPrefix.Items.FindByValue(value));
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
private void Bind()
{
if (ddlStreetPrefix.Items.Count == 0)
{
SqlDataReader rdr = StreetDirectionals.GetDirectionals();
ddlStreetPrefix.DataSource = rdr;
ddlStreetPrefix.DataBind();
ddlStreetPrefix.DataValueField = "StreetSuffixPrefixAbbr";
ddlStreetPrefix.DataTextField = "StreetSuffixPrefixAbbr";
ListItem li = new ListItem("", "");
ddlStreetPrefix.Items.Insert(0, li);
ddlStreetPrefix.SelectedIndex = 0;
}
}
}
The StreetDirectionals class:
public class StreetDirectionals
{
private StreetDirectionals () { }
public static SqlDataReader GetDirectionals ()
{
string sqlText = "SELECT StreetSuffixPrefixAbbr FROM common..tblStreetSuffixPrefix " +
"ORDER BY StreetSuffixPrefixAbbr";
SqlDataReader rdr = SqlClient.ExecuteFetchReturnDataReader( theConnectionString, CommandType.Text, sqlText);
return rdr;
}
}
I will separate out the database interaction inside the StreetDirectionals class as soon as I can figure out how to change its code if I were to transform the Bind() method from my dropdown user control into this:
private void Bind()
{
if (!IsPostBack)
{
**List<StreetDirectionals> sd = StreetDirectionals.GetDirectionals();**
ddlStreetPrefix.DataSource = sd;
ddlStreetPrefix.DataTextField = "StreetSuffixPrefixAbbr";
ddlStreetPrefix.DataValueField = "StreetSuffixPrefixAbbr";
ddlStreetPrefix.DataBind();
}
}
Any assistance would be sooo much appreciated!
public class StreetDirectional
{
public string StreetSuffixPrefixAbbr { get; set; }
public static IEnumerable<StreetDirectional> GetDirectionals ()
{
string sqlText = "SELECT StreetSuffixPrefixAbbr FROM common..tblStreetSuffixPrefix "
+ "ORDER BY StreetSuffixPrefixAbbr";
SqlDataReader rdr = SqlClient.ExecuteFetchReturnDataReader( theConnectionString, CommandType.Text, sqlText);
var list = new List<StreetDirectional>();
while (rdr.Read())
{
var item = new StreetDirectional() { StreetSuffixPrefixAbbr = (string)rdr["StreetSuffixPrefixAbbr"] };
list.Add(item);
}
return list;
}
}
then you can do this
ddlStreetPrefix.DataSource = StreetDirectional.GetDirectionals();

ASP:TextBox Value disappears in postback only when password

I have an asp.net textbox like this:
<asp:TextBox ID="PINPad" runat="server" Columns="6" MaxLength="4"
CssClass="PINTextClass"></asp:TextBox>
It is, as you might have guessed, the text box from an on screen PIN pad. Javascript fills in the values. The page is posted back every five seconds (using an update panel if that matters) to update various other unrelated items on the screen. This works just fine.
However, when I convert it to a password text box, like this:
<asp:TextBox ID="PINPad" runat="server" Columns="6" MaxLength="4"
CssClass="PINTextClass" TextMode="Password"></asp:TextBox>
Then whenever the page posts back, the text box is cleared out on the screen and the textbox is empty (though during the timer event, the value does make it back to the server.)
Any suggestions how to fix this, so that it retains its value during postback?
As a security feature, ASP.NET tries to disallow you from sending the password value back to the client. If you're okay with the security issues (i.e. it's either not really secure information or you're sure that the connection is secure), you can manually set the "value" attribute of the control, rather than using its Text property. It might look something like this:
this.PINPad.Attributes.Add("value", this.PINPad.Text);
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (!(String.IsNullOrEmpty(txtPwd.Text.Trim())))
{
txtPwd.Attributes["value"]= txtPwd.Text;
}
if (!(String.IsNullOrEmpty(txtConfirmPwd.Text.Trim())))
{
txtConfirmPwd.Attributes["value"] = txtConfirmPwd.Text;
}
}
}
here is another way to do it:-
using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebControlLibrary
{
public class PWDTextBox : TextBox
{
public PWDTextBox()
{
this.TextMode = TextBoxMode.Password;
}
public string Password
{
get
{
string val = (string)ViewState["pwd"];
if (string.IsNullOrEmpty(val))
{
return "";
}
else
{
return val;
}
}
set
{
ViewState["pwd"] = value;
}
}
public override string Text
{
get
{
return Password;
}
set
{
Password = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.Text = Password;
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Value, this.Password);
}
}
}
The problem of losing the password in the postback can be avoid making use of Asynchronous JavaScript calls, lets describe a typical scenario for a Login page:
Lets say we have a Login page which allows the user to change the language of its labels when the user choose a language with a dropdownlist
a solution would be to invoke selectedIndexChanged event of the dropdownlist, make a postback which goes to the server and picks up the labels in the chosen language.
in this scenario the field password will be lost due to the security feature of ASP.NET which makes passwords fields not persisted between a postbacks.
This scenario can be solved if the postback is avoided making use of Asynchronous JavaScript Technology and XML (Ajax) calls.
Add a javascript function which will be invoked from the dropdownlist control, in this case this function is assigned to the Command property of the dropdownlist in code behind:
function ValueChanged(div)
{
var table = div.getElementsByTagName("table");
if (table && table.length > 0)
{
var t = table[0].getAttribute('type');
if (t != null && (t == "DropDown"))
{
var inputs = div.getElementsByTagName("input");
if (inputs && inputs.length == 2)
{
{
Translate(inputs[1].value);
}
}
}
}
}
The Translate function takes as parameter the selected option language in the dropdown control and performs the asynchronous call as shown bellow.
function Translate(lang)
{
var request = null;
if (window.XMLHttpRequest)
{
request = new XMLHttpRequest();
if (request.overrideMimeType)
{
request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
if (request == null)
{
return;
}
var url = "GetLoginTranslations.aspx";
request.open('GET', url +'?lang=' + lang, true);
request.setRequestHeader("Cache-Control", "no-cache");
request.setRequestHeader("Pragma", "no-cache");
request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
request.onreadystatechange = function () { TranslateLabels(request); };
request.send(null);
}
the function Translate shown above performs the call and get the results in the specified .aspx page (in this case "GetLoginTranslations.aspx")
when the request is completed and the request.onreadystatechange is set to the function TranslateLabels this function will be executed.
on this way the postback is not executed as before in the event onSelectedIndexChanged of the dropdownlist control.
the TranslateLabels function would look something like :
function TranslateLabels(request)
{
if (request.readyState == 4)
{
if (request.status == 200)
{
if (request.responseXML)
{
var objRoot = request.responseXML.documentElement;
if (objRoot)
{
if (objRoot.nodeName == "strings")
{
for (var i = 0; i < objRoot.childNodes.length; i++)
{
var node = objRoot.childNodes[i];
var elem;
switch (node.getAttribute("id"))
{
case "lbl_login":
elem = document.getElementById("lbl_login");
if (elem)
elem.innerHTML = node.firstChild.nodeValue;
break;
}
///....
}
}
}
}
}
}
the request.responseXML contains the XML built in the page GetLoginTranslations.aspx and the structure of this XML is defined there.
the Page_Load() event in the GetLoginTranslations.aspx should look like:
protected void Page_Load(object sender, EventArgs e)
{
if (Request["lang"] != null)
strLang = Request["lang"];
//init response
Response.Clear();
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(true);
Response.ContentType = "application/xml";
Response.Charset = "utf-8";
XmlTextWriter xml = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8)
{
Formatting = Formatting.None
};
xml.WriteStartDocument();
xml.WriteStartElement("strings");
xml.WriteStartElement("string");
xml.WriteAttributeString("id", "lbl_login");
xml.WriteString(GetTranslation("label_login", strLang));
xml.WriteEndElement();
// ... the other labels
xml.WriteEndElement(); //</strings>
xml.Close();
}
Some other considerations:
set the the property AutoPostback of the dropdownlist to false.
Happens both for view-model properties named 'Password' and 'PIN'. You can bypass the behavior by defining those as:
string Password ;
... rather than:
string Password { get; set; }
If you do so, features such the 'LabelFor' macro displaying 'DisplayAttribute.Name' no longer works, so you'd have to define those directly in the HTML.
Or you can simply name the fields something other than 'Password' or 'PIN'.

Resources