.NET DropDownList的回传被清除后, [英] .net DropDownList gets cleared after postback

查看:269
本文介绍了.NET DropDownList的回传被清除后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经我发疯了一整天。我已经看到了这个问题,突然出现在这里了几次,基本上我有一个下拉列表填充,当它改变了下面的表单 - 基本的东西。在第一个页面加载一切都很好,但是当DropDownList的改变时,它的回传和SelectedIndexChanged事件永远不会触发后完全空白。我相信这一切指向一个视图状态的问题。这里的code ..

This has been driving me nuts all day. I've seen this problem crop up here a few times, essentially I have a drop down list that populates a form below when it's changed - basic stuff. On first page load everything is fine, but when the dropdownlist is changed, it's entirely blank after postback and the SelectedIndexChanged event never fires. I believe it all points to a viewstate problem. Here's the code..

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EditUser.ascx.cs" Inherits="Controls_EditUser" %>
<asp:DropDownList OnSelectedIndexChanged="SelectedIndexChanged" AutoPostBack="true" ID="UsersList" EnableViewState="true"
    runat="server" DataTextField="EXTRANET_USER_EMAIL" DataValueField="EXTRANET_USER_ID">
</asp:DropDownList>

和页面加载...

and the pageload...

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        IEnumerable<ExtranetUser> users = Users();
        UsersList.DataSource = users;
        UsersList.Items.Insert(0, new ListItem("-- Select User --", "0"));
        UsersList.DataBind();
    }
}

在这将是巨大的AP $ P $任何帮助pciated!我敢肯定,这是简单的东西...

Any help on this would be hugely appreciated! I'm sure it's something simple...

推荐答案

编辑:完全新的答案...

Completely new answer...

您将在Page_Init事件的控制?任何晚于这一点,ViewState的将已经被解析并应用到控制页面上,之前的动态添加控件添加。看到这一点: http://msdn.microsoft.com/en-us/library/ ms178472.aspx

Are you adding the control in the Page_Init event? Any later than this and the ViewState will have already been parsed and applied to the controls on the page, before the dynamically added control has been added. See this: http://msdn.microsoft.com/en-us/library/ms178472.aspx

这篇关于.NET DropDownList的回传被清除后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆