2012-07-17 57 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> 

告诉我它是否工作。

相关问题