Call C#.net method in Javascript
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?
精彩评论