How to pass an additional parameter to CascadingDropDown ServiceMethod?

别来无恙 提交于 2019-12-08 13:35:22

问题


I have two chained CascadingDropDowns. Both are working fine. The thing is that in the underlying web methods which are supplying values for DropDwonList I need read one additional parameter. This parameter is needed for setting up the default item for dropdownlist.

I do not know how to pass that parameter or read it. I've read on the Internet about the ContextKey property. But I do not know how to acces it from the WebMethod.

I've tried to get to the session through HttpContext.Current.Session (hoping that I could extract some parameter from the session) but it seams that the Session is different for the WebPage and WebMethod.

So I am lost here, any ideas?


回答1:


You need three things to get the ContextKey to work.

  1. Set UseContextKey property on the CascadingDropDown to true
  2. Change the method signature of your webmethod to accept the contextKey parameter:

public CascadingDropDownNameValue[] GetDropDownContents( string knownCategoryValues, string category, string contextKey) { ... }

NOTE: The parameter has to be exact casing.

  1. Set the ContextKey using JavaScript. The AJAX CascadingDropDown exposes getter/setter for this property in the DOM:

    document.getElementById('idOfCDDL').set_contextKey('valueyouwant');

HTH.




回答2:


Passing Additional arguments Sometimes the action method which provides the JSON for the combobox may need additional arguments. Here is how to pass them to your action: CopyPassing additional arguments to the action method

function onComboBoxDataBinding(e) {
    e.data = $.extend({}, e.data, { customParam: "customValue"});
}



回答3:


In your .cs file write:

cascadingdropdown1.contextKey=<parameter you need>

Then in the web method use that contextKey



来源:https://stackoverflow.com/questions/3838203/how-to-pass-an-additional-parameter-to-cascadingdropdown-servicemethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!