开发者

Using a cascading drop down on the same aspx page as an update panel

I'm using ASP.NET 4.0. I have 2 DropDownList's, a CascadingDropDown (from Ajax Control Toolkit) and an UpdatePanel on the same page.

The drop downs are not within the update panel, and their functionality is working fine (once one option is selected from a DropDownList, the CascadingDropDown does its thing and updates the second DropDownList).

The update panel simply contains a button and a text box. When the button is clicked, an event handler is in place to set the text on the text box.

The update panel works fine when the portion of code with the drop downs in is commented out, but as soon as the drop downs are uncommented, the clicking the button no longer refreshes the text box, no post back occurs.

The aspx page:

<asp:ScriptManager ID="scriptManager" runat="server">
</asp:ScriptManager>

<div>
    <label for="<%= ddOne.ClientID %>" >DD one</label>
    <asp:DropDownList ID="ddOne" runat="server">
        <asp:ListItem Text="" Value="-1" />
        <asp:ListItem Text="Option one" Value="1" />
        <asp:ListItem Text="Option two" Value="2" />
        <asp:ListItem Text="Option t开发者_Go百科hree" Value="3" />
    </asp:DropDownList>
</div>

<ajaxToolkit:CascadingDropDown 
        ID="ccdOne"
        runat="server"
        ParentControlID="ddOne"
        TargetControlID="ddTwo" 
        Category="Category" 

        ServicePath="SomeWebService.asmx"
        ServiceMethod="SomeWebMethod"
        EmptyText="None available"
        EmptyValue="-1"
        LoadingText="Loading..." />

<div>
    <label for="<%= ddTwo.ClientID %>">DD two</label>
    <asp:DropDownList ID="ddTwo" runat="server">
    </asp:DropDownList>
</div>

<asp:UpdatePanel runat="server" ID="upPanelOne">

    <ContentTemplate>

        <asp:Button ID="aButton" runat="server" Text="Click me" onclick="aButton_Click" />
        <asp:TextBox ID="txtOne" runat="server" />

    </ContentTemplate>


</asp:UpdatePanel>

The code behind:

    protected void aButton_Click(object sender, EventArgs e)
    {
        txtOne.Text = "Hello world";
    }

Any ideas?

Notes:

UpdatePanel on its own works fine

DropDownLists with cascading drop down works fine

When DropDownLists used on the same page as the update panel, but not in the update panel, the update panel stops working?


Add following tags to your updatepanel

<Triggers>
            <asp:AsyncPostBackTrigger ControlID="aButton" EventName="Click" /
        </Triggers>

So it should be something like this:

<asp:UpdatePanel runat="server" ID="upPanelOne">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="aButton" EventName="Click" /
        </Triggers>
        <ContentTemplate>
            <asp:Button ID="aButton" runat="server" Text="Click me" onclick="aButton_Click" />
            <asp:TextBox ID="txtOne" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>


I had the same problem, but I followed the Ben comment which tells to set the EnableEventValidation="false" have cleared my issue and it's now working fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜