locked
List , class RRS feed

  • Question

  • User-158363518 posted

    hi

    i have 100 Status Code like this 

    error code , Description

    100 , some text | 101 ,some text |102...600 , some text 

    when i execute any thing , result is a code in range 100 - 600

    how i can create a class that get error code and return Description . 

    how i can organize this (600 error ) And return the error description quickly

    thanks

    Wednesday, November 14, 2018 9:55 AM

Answers

  • User-369506445 posted

    hi

    you can create a class below like :

    public class CustomError
            {
                public int Code { get; set; }
                public string Description { get; set; }
    
    
                public static List<CustomError> Get()
                {
                    return new List<CustomError>()
                    {
                        new CustomError {Code = 100 , Description = "some text1"},
                        new CustomError {Code = 102 , Description = "some text2"},
                        new CustomError {Code = 103 , Description = "some text3"},
                        new CustomError {Code = 104 , Description = "some text4"},
    .
    .
    . }; } }

    and use

     protected void Page_Load(object sender, EventArgs e)
            {
                var description = CustomError.Get().Single(x => x.Code == 102).Description;
            }

    result

    some text2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 12:33 PM
  • User839733648 posted

    Hi csajad,

    I suggest you could use webservice to define a function to get the list of code content in webform.

    And use Ajax to show the result on your page like below.

    JS.

        $.ajax({
          type: "POST",
          url: "TestCodeService.asmx/GetAllCodes",
          data: "{}",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(response) {
            var codes = response.d;
    
          },
        });

    Code behind.

    [ScriptService]
    public class TestCodeService : WebService
    {
        List<TestCode> Testcodes = new List<TestCode>{
        new TestCode{id="100",content="some text"},
        new TestCode{id="101",content="some text"},
        new TestCode{id="102",content="some text"},
                          ......
        new TestCode{id="600",content="some text"},
        };
     
        [WebMethod]
        public List<TestCode> GetAllCodes()
        {
            return Testcodes;
        }
    
    }
    
    public class TestCode
    {
        public int id;
        public string content;
    }
    
     

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2018 7:14 AM

All replies

  • User475983607 posted

    hi

    i have 100 Status Code like this 

    error code , Description

    100 , some text | 101 ,some text |102...600 , some text 

    when i execute any thing , result is a code in range 100 - 600

    how i can create a class that get error code and return Description . 

    how i can organize this (600 error ) And return the error description quickly

    thanks

    Unclear... can you clarify the problem you are trying to solve.  Are you trying to split a string by "|" then  ","?

    Perhaps create a table to hold the data.

    Wednesday, November 14, 2018 12:28 PM
  • User-369506445 posted

    hi

    you can create a class below like :

    public class CustomError
            {
                public int Code { get; set; }
                public string Description { get; set; }
    
    
                public static List<CustomError> Get()
                {
                    return new List<CustomError>()
                    {
                        new CustomError {Code = 100 , Description = "some text1"},
                        new CustomError {Code = 102 , Description = "some text2"},
                        new CustomError {Code = 103 , Description = "some text3"},
                        new CustomError {Code = 104 , Description = "some text4"},
    .
    .
    . }; } }

    and use

     protected void Page_Load(object sender, EventArgs e)
            {
                var description = CustomError.Get().Single(x => x.Code == 102).Description;
            }

    result

    some text2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 12:33 PM
  • User839733648 posted

    Hi csajad,

    I suggest you could use webservice to define a function to get the list of code content in webform.

    And use Ajax to show the result on your page like below.

    JS.

        $.ajax({
          type: "POST",
          url: "TestCodeService.asmx/GetAllCodes",
          data: "{}",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(response) {
            var codes = response.d;
    
          },
        });

    Code behind.

    [ScriptService]
    public class TestCodeService : WebService
    {
        List<TestCode> Testcodes = new List<TestCode>{
        new TestCode{id="100",content="some text"},
        new TestCode{id="101",content="some text"},
        new TestCode{id="102",content="some text"},
                          ......
        new TestCode{id="600",content="some text"},
        };
     
        [WebMethod]
        public List<TestCode> GetAllCodes()
        {
            return Testcodes;
        }
    
    }
    
    public class TestCode
    {
        public int id;
        public string content;
    }
    
     

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2018 7:14 AM