I'm new to C#.
I've been tasked to create this application and I felt like I was doing well. Do to proprietary information I cannot give too many details but I do need some direction.
I'm using Silverlight 5 with C# to build a business application. Here's the deal:
I have a value brought in from my DB based on a LINQ query that populates a text block to display the value so I can see it. To this point it all works, I change the value in the DB the value changes in the text block. The value in the DB is a bit which translates to text in my text block (True,False)...great...works!
When I attempt to take that value and convert it to Bool however, it fails...every time. All my searching and research has resulted in great ideas that seem to work for others. I was pretty sure I was using it correctly, obviously not however.
Here's the code where my primary issue is located.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
flag.Text = bool.TryParse(hiddenSts.Text, out allowed).ToString();
bool isAllowed;
if(!bool.TryParse(hiddenSts.Text, out isAllowed))
{
String Name = WebContext.Current.User.DisplayName.ToString().Substring(8);
String Auth = WebContext.Current.User.IsAuthenticated.ToString();
userNotAllowed accessDenied = new userNotAllowed();
accessDenied.userIdentity.Text = Name;
accessDenied.authentication.Text = string.Concat(Auth, " | Win_Auth");
accessDenied.Show();
}
}
Upon navigating to this page my code takes the value stored in my text block (hiddenSts), which is True or False depending on my bit value in the DB, and attempts the Boolean conversion on the string in the text block. So when the value is false I have a child window pop up and a redirect between pages...all working when I hard code any values. TryParse is the only one not acting as I thought it would.
-flag is a text box to see the return of the TryParse (always False)
-hiddenSts is a text block to see the value from the DB based on a query
Any direction would be greatly appreciated.