2012-07-17 55 views
1

如何在沒有觸發回發的情況下更改asp.net dropdownlist的選定值?在不觸發回發的情況下更改asp.net dropdownlist的選定值

我已經嘗試將autopostback設置爲false,但在選擇下拉列表中的其他選項時,選項上的「selected」屬性不會更改。

我見過一些使用updatepanel的示例,我試過這個成功,但由於頁面上的其他javascript和jquery功能,我不能使用這個沒有很多其他功能的麻煩..

代碼更新

<asp:DropDownList ID="USERS" DataTextField="NAME" DataValueField="ID" runat="server" 
        Width="150px"> 
    </asp:DropDownList> 
+0

它的默認本質是不回發......我不知道爲什麼你遇到問題,因爲我已經使用它們沒有副作用。你可以發佈標記嗎? – 2012-07-17 19:59:02

+1

您的EnableViewState屬性設置爲true?您是否在嘗試讀取所選項目(例如,使用IsPostback上的條件)之前避免重新填充下拉菜單? – mamoo 2012-07-17 20:01:38

+0

正如你所見,我已經在上面發佈了我的下拉列表標記。當我更改下拉列表中的值I並檢查該元素時,它仍然是第一個具有「selected」屬性的項目。 – ffffff01 2012-07-18 05:29:35

回答

0

嘗試AJAX與ASP:的UpdatePanel和ASP:標籤的UpdateProgress。如果您已經嘗試過,請向我們展示您的代碼,以便我們提供幫助。

+0

正如我在我的問題中所寫的,我不能使用updatepanel,因爲它在jquery時出現很多其他問題使用.. – ffffff01 2012-07-18 05:40:56

+1

它不會影響其他jQuery,正確指定ID屬性。 – Abhijeetchindhe 2012-07-18 05:43:15

0

讓我再解釋一下您詳細...

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
<asp:DropDownList ID="DropDownList1" runat="server"> 
</asp:DropDownList> 
    </ContentTemplate> 

,並添加如果你想

<asp:UpdateProgress ID="UpProDisp" runat="Server" AssociatedUpdatePanelID="UpdatePanel1" OnLoad="UpdatePanelProdDisp_Load"> 
      <ProgressTemplate> 
      </ProgressTemplate> 
</asp:UpdateProgress> 

還加模態彈出

<asp:ModalPopupExtender ID="modalExtender" runat="server" TargetControlID="UpProDisp" PopupControlID="Panel1" DropShadow="true" BackgroundCssClass="modalBackground"> 
</asp:ModalPopupExtender> 
<asp:Panel ID="Panel1" runat="server" CssClass="modalExtender"> 
    <img alt="Processing" src="../Images/Processing.jpg" /> 
     <br /> 
    <asp:Label ID="lblProcessing" runat="server" Text="Processing..." CssClass="TitleBar"></asp:Label> 
    </asp:Panel> 

與更新進度以下JavaScript代碼...

<script type="text/javascript"> 
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showPopup); 
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hidePopup); 

function showPopup(sender, args) { 
var ModalControl = '<%= modalExtender.ClientID %>'; 
$find(ModalControl).show(); 
} 

function hidePopup(sender, args) { 
var ModalControl = '<%= modalExtender.ClientID %>'; 
$find(ModalControl).hide(); 
} 
</script> 

告訴我它是否工作。

相關問題