Hi.
I have a 2 tier control. The Website hosts the public facing .ascx which inherits it's server side .cs (which inherits UserControl).
All of my data access is handled by my server side control, and all of the controls are populated by my public facing control.
This control handles the users roles on the website. The user can access this page via the url [host]/Roles and select a user from the dropdown. They can also access it via the url [host]/Roles/[username] which will automatically select the user from the dropdown.
When the page is loaded with a username, or when a username is selected from the dropdown, the server side control saves the username to the viewstate for later reference.
When the username is selected from the dropdown then all works ok.
When the username is selected from the url then it does not maintain the viewstate
I'm sure this has to do with my two tier control, but I don't know how to fix it.
I tested adding "test":"test" to the viewstate if !IsPostback on the public facing side and that item is maintained.
What am I doing wrong?
Username Property:
...
protected string Username
{
get
{
return ViewState.GetStateItem<string>("Username");
}
set
{
ViewState.SetStateItem("Username", value);
}
}
...
public static T GetStateItem<T>(this StateBag viewState, string key)
{
object obj = viewState[key];
if (obj == null)
return default(T);
if (obj.GetType().IsAssignableFrom(typeof(T)))
return (T)obj;
return default(T);
}
public static void SetStateItem<T>(this StateBag viewState, string key, T value)
{
viewState[key] = value;
}