Note that there are some explanatory texts on larger screens.

plurals
  1. POmanually adding ajax control toolkit cascading drop down
    primarykey
    data
    text
    <p>Visual Studio 2010, .NET Framework 4.0 Trying to manually add an AjaxControlToolkit CascadingDropDown extender to a webpage dynamically. The web page has a placeholder. When it posts back the controls are built dynamically and added to the placeholder. I have regular ASP.NET drop down list boxes that I want to add CascadingDropDown extender to.</p> <pre><code>myCascadingDropDown = New AjaxControlToolkit.CascadingDropDown myCascadingDropDown.ID = "cdd_" &amp; myDisplayedField.ControlID myCascadingDropDown.BehaviorID = "cdd_" &amp; myDisplayedField.ControlID myCascadingDropDown.TargetControlID = myDisplayedField.ControlID myCascadingDropDown.Category = myDisplayedField.ControlID myCascadingDropDown.PromptText = "Select " &amp; aField.Caption myCascadingDropDown.ServicePath = "CascadingDropDown.asmx" myCascadingDropDown.ServiceMethod = "DropDownListBoxChanged" myPanelForFields.Controls.Add(myCascadingDropDown) </code></pre> <p>The error is the last line where it is adding the CascadingDropDown. The error is:</p> <blockquote> <p>Value cannot be null. Parameter <code>name</code>: No target control is set for the <code>CascadingDropDown</code> extender.</p> </blockquote> <p>And if you look at the property TargetControl on myCascadingDropDown it is null (nothing). But you can not set it (it is read only). I assumed that since I set TargetControlID that ASP.NET would set TargetControl from the TargetControlID.</p> <p>Any ideas or suggestions?</p> <p>More complete exception:<br> System.ArgumentNullException was unhandled by user code Message=Value cannot be null.<br> Parameter name: No target control is set for the CascadingDropDown extender. ParamName=No target control is set for the CascadingDropDown extender.<br> Source=AjaxControlToolkit<br> StackTrace:<br> at AjaxControlToolkit.CascadingDropDown.CascadingDropDown_ClientStateValuesLoaded(Object sender, EventArgs e)<br> at AjaxControlToolkit.ExtenderControlBase.LoadClientStateValues()<br> at AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e)<br> at System.Web.UI.Control.LoadRecursive()<br> at System.Web.UI.Control.AddedControl(Control control, Int32 index)<br> at System.Web.UI.ControlCollection.Add(Control child) </p> <p><strong>ANSWER in VB.NET:</strong></p> <p>Yuriy Rozhovetskiy nailed it. I am programming this application in vb.net so first I created a global variable (my functions in this class are shared/static): </p> <pre><code>Shared ControlToResolve As System.Web.UI.Control </code></pre> <p>Then the code I created was: </p> <pre><code>myCascadingDropDown = New AjaxControlToolkit.CascadingDropDown myCascadingDropDown.ID = "cdd_" &amp; myDisplayedField.ControlID myCascadingDropDown.BehaviorID = "cdd_" &amp; myDisplayedField.ControlID myCascadingDropDown.TargetControlID = myDisplayedField.ControlID myCascadingDropDown.Category = myDisplayedField.ControlID myCascadingDropDown.PromptText = "Select " &amp; aField.Caption myCascadingDropDown.ServicePath = "CascadingDropDown.asmx" myCascadingDropDown.ServiceMethod = "DropDownListBoxChanged" ControlToResolve = myBSCComboBox AddHandler myCascadingDropDown.ResolveControlID, AddressOf myCascadingDropDown_ResolveControlID myPanelForFields.Controls.Add(myCascadingDropDown) </code></pre> <p>then the handler is: </p> <pre><code>Shared Sub myCascadingDropDown_ResolveControlID(sender As Object, e As ResolveControlEventArgs) e.Control = ControlToResolve End Sub </code></pre> <p>I defined the TargetControl of the CascadingDropDown as "ControlToResolve". I set ControlToResolve to the target Drop Down List Box before I add the CascadingDropDown to the panel holding the controls. When I add the CascadingDropDown, it calls the handler myCascadingDropDown_ResolveControlID which assigns the drop down list box to the CascadingDropDown.Target</p> <p>My web service looks like: </p> <pre><code>&lt;System.Web.Services.WebService(Namespace:="http://tempuri.org/")&gt; _ &lt;System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ &lt;System.Web.Script.Services.ScriptService()&gt; _ &lt;ToolboxItem(False)&gt; _ Public Class CascadingDropDown Inherits System.Web.Services.WebService &lt;WebMethod(EnableSession:=True)&gt; _ Public Function DropDownListBoxChanged(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() End Function </code></pre> <p>and it calls this web service with my ControlID every time I need values in one of the drop down list boxes. BTW - using the ControlID I can tell which drop down list box wants data, if it is a parent or child drop down list box and can go get the data. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload