How to Pass Control as Parameter from javascript to server side
I Want to Pass Control i.e dropdown as Parameter from javascript to server side.
e.g
My Server Side Code
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static void StatusSet(string iMode, DropDownList ddList)
{
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 (iMode == "i")
{
ddList.DataSource = iListStatus.Take(3);
}
else
{
ddList.DataSource = iListStatus.Take(2);
}
}
and Client Side Code is PageMethods.StatusSet(modeIndex, $("#ddlStatus"));
What you are trying to do is not possible. DropDownList is an ASP.NET server-side control and does not exist in your browser. Even if you could create something that resembled a serialized version of the dropdownlist in your javascript and passed it to the page method, databinding on it would not have any effect on your dropdownlist in the browser.
You have two choices about doing what you want to do (update the list of items in the dropdown on the client):
- Have your page method pass back the list items in some form to your javascript code on the client where it can load them into the dropdown.
- Use an UpdatePanel (not PageMethods) and have your server-side code use databinding and update the dropdownlist contents.
精彩评论