Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:56:02+00:00 2026-06-10T04:56:02+00:00

I have a method in C#, which creates a JSON object of the user

  • 0

I have a method in C#, which creates a JSON object of the user credentials.
Below is the CS file.

public string CreateLoginjson(string strErrorType, bool blIsAuthenticated)
{
    StringBuilder sbLoginJson = new StringBuilder();
    if (blIsAuthenticated)
    {
        sbLoginJson.Append("{LoginSuccess:1");
    }
    else
    {
        sbLoginJson.Append("{LoginSuccess:0");
    }

    if (strErrorType != string.Empty)
    {
        if (strErrorType.TrimEnd(new char[] { ',' }) == "Token" ||
                strErrorType.TrimEnd(new char[] { ',' }) == "BlankToken")
        {
            sbLoginJson.Append(",txtTestTokenNumber1:\"Error\"");
            sbLoginJson.Append(",txtTestTokenNumber2:\"Error\"");
            sbLoginJson.Append(",txtTestTokenNumber3:\"Error\"");
            sbLoginJson.Append(",txtTestTokenNumber4:\"Error\"");

        }


        if (strErrorType.TrimEnd(new char[] { ',' }) == "Password")
        {
            sbLoginJson.Append(",txtPassword:\"Error\"");

        }

        if (strErrorType.TrimEnd(new char[] { ',' }) == "UserName")
        {
            sbLoginJson.Append(",UserName:\"Error\"");

        }
        string strLoadErrorControlMessage = LoadErrorControl(strErrorType,
                string.Empty);

        if (strLoadErrorControlMessage!= string.Empty)
        {
            sbLoginJson.Append(",ErrorMessage:
            '" + strLoadErrorControlMessage + "'");
        }
    }
    sbLoginJson.Append("}");

    var LoginJson = sbLoginJson.ToString();
    return LoginJson;
}

Now, I need to pass the LoginJson to a JS function that checks if incorrect credentials are provided, this function finds the control & adds an attribute to it
JS

function GetLoginJson(strLoginJson) {
    if (strLoginJson != '' && strLoginJson != undefined) {
        var objLoginJson = strLoginJson;

        if (objLoginJson.LoginSuccess == "1") {

        }
        else if (objLoginJson.LoginSuccess == "0") {

            if (objLoginJson.txtUserName != '' 
                 && objLoginJson.txtUserName != undefined) 
            {
                $('#txtUserName').attr("class", objLoginJson.txtUserName);
            }
            else 
            {
                $('#txtUserName').attr("class", "Input");
            }

            if (objLoginJson.txtPassword != '' 
                 && objLoginJson.txtPassword != undefined) 
            {
               $('#txtPassword').attr("class", objLoginJson.txtPassword);
            }
            else 
            {
                $('#txtPassword').attr("class", "Input");
            }
            if (objLoginJson.txtTestTokenNumber1 != '' 
                  && objLoginJson.txtTestTokenNumber1 != undefined) 
            {
                $('#txtTestTokenNumber1').attr("class", 
                                                objLoginJson.txtTestTokenNumber1);
            }
            else 
            {
                $('#txtTestTokenNumber1').attr("class", "Error");
            }
            if (objLoginJson.txtTestTokenNumber2 != '' 
                  && objLoginJson.txtTestTokenNumber2 != undefined) 
            {
               $('#txtTestTokenNumber2').attr("class", 
                                               objLoginJson.txtTestTokenNumber2);
            }
            else 
            {
                $('#txtTestTokenNumber2').attr("class", "Error");
            }

            if (objLoginJson.txtTestTokenNumber3 != '' && 
                 objLoginJson.txtTestTokenNumber3 != undefined) {
                $('#txtTestTokenNumber3').attr("class", 
                                                objLoginJson.txtTestTokenNumber3);
            }
            else 
            {
                $('#txtTestTokenNumber3').attr("class", "Error");
            }
            if (objLoginJson.txtTestTokenNumber4 != '' && 
                  objLoginJson.txtTestTokenNumber4 != undefined) {
                $('#txtTestTokenNumber4').attr("class", 
                                                objLoginJson.txtTestTokenNumber4);
            }
            else 
            {
                $('#txtTestTokenNumber4').attr("class", "Error");
            }

            $('#ErrorControl').html('');

        }
    }
}

I want to pass the JSON variable from the CS to this jQuery statement `$(‘#ErrorControl’).html(”);’

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:56:04+00:00Added an answer on June 10, 2026 at 4:56 am

    I finally wrote :
    CS file as

    public string CreateLoginjson(string strErrorType, bool blIsAuthenticated)
    {
        StringBuilder sbLoginJson = new StringBuilder();
        if (blIsAuthenticated)
        {
            sbLoginJson.Append("{LoginSuccess:1");
        }
        else
        {
            sbLoginJson.Append("{LoginSuccess:0");
        }
    
        if (strErrorType != string.Empty)
        {
            if (strErrorType.TrimEnd(new char[] { ',' }) == "Token" || strErrorType.TrimEnd(new char[] { ',' }).Split(new char[] { ',' }).Contains("BlankToken"))
            {
                sbLoginJson.Append(",txtTestTokenNumber1:\"Error\"");
                sbLoginJson.Append(",txtTestTokenNumber2:\"Error\"");
                sbLoginJson.Append(",txtTestTokenNumber3:\"Error\"");
                sbLoginJson.Append(",txtTestTokenNumber4:\"Error\"");
    
            }
    
            if (strErrorType.TrimEnd(new char[] { ',' }) == "Password" ||  strErrorType.TrimEnd(new char[] { ',' }).Split(new char[] { ',' }).Contains("BlankPassword"))
            {
                sbLoginJson.Append(",txtPassword:\"Error\"");
    
            }
    
            if (strErrorType.TrimEnd(new char[] { ',' }) == "UserName" ||  strErrorType.TrimEnd(new char[] { ',' }).Split(new char[] { ',' }).Contains("BlankUserName"))
            {
                sbLoginJson.Append(",txtUserName:\"Error\"");
            }
    
            string strLoadErrorControlMessage = LoadErrorControl(strErrorType, string.Empty);
    
            if (strLoadErrorControlMessage != string.Empty)
            {
                PageTestApplicationLogin objPageTestApplicationLogin = new PageTestApplicationLogin(objClientConfiguration);
                sbLoginJson.Append(",ErrorMessage:'" + objPageTestApplicationLogin.GetTestApplicationLoginErrorHtml("", strLoadErrorControlMessage).Replace("'", "\"") + "'");
            }
            sbLoginJson.Append("}");
        }
        var LoginJson = sbLoginJson.ToString();
        return LoginJson;
    }
    

    JS file :

    if (objLoginJson.ErrorMessage != '' && objLoginJson.ErrorMessage != undefined) {
        $('#ErrorControl').html(objLoginJson.ErrorMessage);
        $('#ErrorControl').find('#tblLoginError').css('display', 'block');
    }
    else {
        $('#ErrorControl').html("");
        $('#ErrorControl').find('#tblLoginError').css('display', 'none');
    }
    

    Thank you all for your Suggestions.. Cheers ….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ASP.NET forms webapplication using C#. I have a method which creates
I have a function called CreateCriteriaExpression that takes a json string and creates a
I have a Method that creates List<SomeObject> . The Collection is JSON serialized via
i have a JSP file in which i have declared a method which return
I have a winforms, and it connecting wit webservice. Webservice has method which create
I have a web service method in which I create a particular type of
I create small application which is media player. I have method where I have
I have created a class library called AddServiceLibrary in which I have a method
Hi I want to create a WCF service that have login method, which is
We have repositories which have a Save method. They also throw a Created event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.