开发者

Call C#.net method in Javascript

开发者 https://www.devze.com 2023-03-05 03:57 出处:网络
I Have Method in Code behind(C#) and Want to call this method inside the javascript. My Code in C# private void StatusSet()

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
    }
}


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消