TroyCrowe
asked on
Better Solutions
Hey everyone,
I am looking for a better way of accomplishing my task. My thought process today is a little out of wack and I am getting frustrated so I am searching for answers. I have created a custom error class. When applying an error message, for example account not created, I am passing an int value through the query string. The problem I am dealing with is how to keep the retrieving of the message value to display in a label's text without having to use a cumbersome switch statement. I tried assigning the values to an enum, which I do not know enough about, but I have found that not to be a good way to handle it; at least it does not seem to be. The code below is a smaller version of what I have going on.
I am looking for a better way of accomplishing my task. My thought process today is a little out of wack and I am getting frustrated so I am searching for answers. I have created a custom error class. When applying an error message, for example account not created, I am passing an int value through the query string. The problem I am dealing with is how to keep the retrieving of the message value to display in a label's text without having to use a cumbersome switch statement. I tried assigning the values to an enum, which I do not know enough about, but I have found that not to be a good way to handle it; at least it does not seem to be. The code below is a smaller version of what I have going on.
public class Messages
{
public static string ItemConfigNotFound = "Items configuration section could not be found";
public static string ItemProviderInstantiationError = "Items default provider could not be instantiated";
public static string CategoryIdUndefined = "Category 'Id' is not defined";
public static string CategoryTitleUndefined = "Category 'Title' is not defined";
public static string ItemIdUndefined = "Item 'id' not defined";
public static string ItemTitleUndefined = "Item 'title' not defined";
public static string ItemTitleIsNull = "Title must be a non null, non-empty string";
public static string ItemRequiredAttributesMissing = "Some of the required attributes of Item are NULL in the Items table";
public static string CategoryRequiredAttributesMissing = "Some of the required attributes of Category are NULL in the Category table";
public static string NewsConfigSectionNotFound = "News configuration section could not be found";
}
//Error page receives a query string with an interger value named errMsg
if (Request.QueryString["Message"] != "")
{
errMsg = Request.QueryString["Message"];
}
switch (errMsg)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
}
//this is the problem: I have 24 error messages. I would like to have more efficient code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solution is a good solution. Thanks
ASKER