Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
    }
}
share|improve this question
Have a look similar one stackoverflow.com/questions/5828803/… – Muhammad Akhtar May 12 '11 at 12:13
add comment (requires an account with 50 reputation)

1 Answer

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?

share|improve this answer
Then is it mandatory to make make method Static in server Side – Dinesh Sharma May 12 '11 at 12:17
yah, you have to make it static. – Muhammad Akhtar May 12 '11 at 12:20
@Dines Sharma, see an updated answer – šljaker May 12 '11 at 12:23
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.