-1

I Have Method in Code behind(C#) and Want to call this method inside the javascript.

My Code in C#

    private void StatusSet()
    {            
        List<StatusHandler> iListStatus = new List<StatusHandler>();

        iListStatus.Add(new StatusHandler('A', "Active"));
        iListStatus.Add(new StatusHandler('I', "InActive"));
        iListStatus.Add(new StatusHandler('L', "All"));

        if (hdnMode.Value == "i")
        {
            ddlStatus.DataSource = iListStatus.Take(2);
        }
        else
        {
            ddlStatus.DataSource = iListStatus.Take(3);
            if (lnkBtnUpdate1.Visible == true)
            {
                ddlStatus.DataSource = iListStatus.Take(2);
            }
        }
    }

Javascript :

function GetMode(modeIndex) {
    if (modeIndex == 'i') {
        StatusSet(); //How to Call in Javascript
    }
}
1

1 Answer 1

3

You can't call this directly from javascript.
You must use Ajax.

EDIT:

Here you can see how to return a list as a JSON: asp.net web forms json return result
Here you can see how to populate dropdown list: jQuery: Best practice to populate drop down?

Sign up to request clarification or add additional context in comments.

2 Comments

Then is it mandatory to make make method Static in server Side
yah, you have to make it static.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.