2011-08-03 64 views
2

我正在使用ASP.NET 4.0。我在同一頁面上有2 DropDownListCascadingDropDown(來自Ajax Control Toolkit)和UpdatePanel在同一aspx頁面上使用級聯下拉作爲更新面板

的下拉列表不更新面板內,它們的功能是工作的罰款(後一個選項是從一個DropDownList選中,CascadingDropDown就執行和更新第二DropDownList)。

更新面板只包含一個按鈕和一個文本框。點擊按鈕後,會有一個事件處理程序來設置文本框上的文本。

當下拉菜單中的部分代碼被註釋掉時,更新面板可以正常工作,但一旦下拉列表未被註釋掉,單擊該按鈕不再刷新文本框,就不會發生回發。

aspx頁面:

<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 three" 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> 

背後的代碼:

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

任何想法?

注:

UpdatePanel精細

DropDownList s的級聯自己的作品下拉正常工作

當同一頁面爲更新面板上的DropDownList S,但不是在更新面板,更新面板停止工作?

+0

我看到你找到了錯誤的原因。請發表你的發現作爲對這個問題的回答,並接受它作爲答案。這樣做可以幫助其他患有同樣問題的患者。 – rcdmk

回答

0

添加以下代碼到你的updatepanel

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

因此,它應該是這樣的:

<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> 
+0

因爲按鈕是更新面板中的子控件,所以我不認爲需要像這樣明確添加觸發器......但我以任何方式嘗試了它,就像之前一樣,它在DropDownList的代碼被註釋但是當他們的代碼是在他們不工作:( – Ben

+0

好吧我想通了什麼問題顯然,如果你添加一個元素到服務器控件下拉列表通過javascript在回發你會得到一個異常拋出告訴你關閉事件驗證或一些這樣的消息,它似乎沒有任何事情發生,因爲我正在使用更新面板,所以我從來沒有看到錯誤消息。 /03/20/asp-net-event-validation-and-invalid-callback-or-postback-argument.aspx詳情 – Ben

+0

感謝您分享.... – Waqas

0

我有同樣的問題,但我跟着奔評論告訴設置EnableEventValidation="false"已經清除我的問題,現在工作正常。

相關問題