Solved

Enable event validation with AJAX cascading drop downs

Posted on 2010-11-10
6
1,001 Views
Last Modified: 2012-05-10
My question is regarding the solution on this page http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_25373688.html

I have implemented the solution but when I try to reference the controls after a postback they are not available.

Eg.
 
   Protected Sub bSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bSearch.Click

       ....

       If nvddl1.SelectedValue <> "" Then id = nvddl1.SelectedValue
       ....

    End Sub

Gives the error Object reference not set to an instance of an object.

Thanks,
Karen
0
Comment
Question by:KarenMcC
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What is Nothing (nvddl1 or SelectedValue)?  How are you binding the CascadingDropDown?  Is is a dynamic or static control?
0
 

Author Comment

by:KarenMcC
Comment Utility
nvddl1 is nothing.

This is example code:

    Private nvddl1 As NoValidationDropDownList
    Private nvddl2 As NoValidationDropDownList
    Private cdd1 As AjaxControlToolkit.CascadingDropDown
    Private cdd2 As AjaxControlToolkit.CascadingDropDown

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        nvddl1 = New NoValidationDropDownList()
        nvddl1.ID = "nvddl1"
        ph1.Controls.Add(nvddl1)

        cdd1 = New AjaxControlToolkit.CascadingDropDown()
        cdd1.ID = "cdd1"
        cdd1.TargetControlID = "nvddl1"
        cdd1.Category = "country"
        cdd1.ServicePath = "~/RegionService.asmx"
        cdd1.ServiceMethod = "GetCountries"
        cdd1.SelectedValue = 4
        ph1.Controls.Add(cdd1)

        nvddl2 = New NoValidationDropDownList()
        nvddl2.ID = "nvddl2"
        ph1.Controls.Add(nvddl2)

        cdd2 = New AjaxControlToolkit.CascadingDropDown()
        cdd2.ID = "cdd2"
        cdd2.TargetControlID = "nvddl2"
        cdd2.ParentControlID = "nvddl1"
        cdd2.Category = "region"
        cdd2.ServicePath = "~/RegionService.asmx"
        cdd2.ServiceMethod = "GetRegionsForCountry"
        ph1.Controls.Add(cdd2)


    End Sub

I would prefer to add the control in design, but do not know how to do that.

Thanks.
k.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Is NoValidationDropDownList your own custom extender/control?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:KarenMcC
Comment Utility
Yes...

Public Class NoValidationDropDownList
    Inherits DropDownList
End Class

The only purpose of this is so that the control is not validated by EnableEventValidation="true".
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Is this a "custom control" or a "user control"?  If it is a custom control, I would create another control library project, put the custom control into the library, and create a project reference.  The Visual Studio.NET IDE should recognize this, and add the control to the tool box, so that you can drag and drop.
0
 

Author Comment

by:KarenMcC
Comment Utility
Thanks very much. This works very well.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now