views:

90

answers:

1

Hi. 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  A: 

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.

RPM1984
what the..? no code sample? SO must be doing maintenance. :)
RPM1984
Thank you, so there is a hope for me! But I am to unexperienced to understand one thing. How through JavaScript I can get to for example datasource to pass value from datasource into set_contextKey('value_from_datasource_row'). And where and when on the webpage should I run document.getElemntById method?
Wodzu
It depends what you want to set as the context key - your question says "default item". Dont know what that is, but im guessing it's something static, which begs the question why you need to pass it through at all. As a starting point though, you could attach a "selectedIndexChanged" client-side javascript event handler to the DDL, and set the contextkey there.
RPM1984
when you say datasource, do you mean the DDL? Remember, JavaScript is all client-side, there is no "data source", only HTML - so in the case of a DDL there will be "options". So you need to set the contextkey to the elected index of the DDL when they make a selection.
RPM1984
Thank you for your interest:) I'll try to be more specific. Just forget about the default item thing. Assume that I want to pass additional parameter, to the method:) By DataSource I've meant a DataSource object which is provided by ASP framework:) - you can connect to it a GridView and display some data. Now my question is: when the page is rendered, drop down lists are filled automatically by the AJAX without any user interaction. How to pass at that time value as contextKey, I want to take that value from one of the rows of generated datasource. Do you understand me now?
Wodzu
It sounds like you want to pass the contextkey to the web method for the FIRST CDDL (ie the one that is executed automatically when the page is rendered). If this is the case, why don't you set the contextKey server-side (on Page_PreRender for example) ? You would set it client-side with JavaScript when you want to "change" this contextKey based on user selections, but if it's an auto-call from AJAX, just set it server-side (ajaxCDDL.ContextKey = "foo")
RPM1984
Yeah, I've came to this conlcussion yesterday. Thanks for yout help :)
Wodzu
:) No problems, glad you got it sorted.
RPM1984