-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
    }
}
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
Dinesh Sharma
  • 117
  • 4
  • 5
  • 16
  • Have a look similar one http://stackoverflow.com/questions/5828803/how-to-call-code-behind-server-method-from-a-client-side-javascript-function/5828840#5828840 – Muhammad Akhtar May 12 '11 at 12:13

1 Answers1

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?

Community
  • 1
  • 1
šljaker
  • 7,294
  • 14
  • 46
  • 80