DropDownList的中的UpdatePanel [英] DropDownList in UpdatePanel

查看:91
本文介绍了DropDownList的中的UpdatePanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。

在我的项目,我已经放在一个DropDownList在updatepanel.what我想要做的是从DropDownList中选择一个值,并用它在会话中。

in my project i have placed a dropdownlist in an updatepanel.what i wanted to do is to select a value from dropdownlist and use it in a session.

但无论我做什么,它总是会放弃,因为不检查启用的AutoPostBack。而当我做到这一点,这将刷新页面,所以这个心不是我想要的了我的空值。

but whatever i do,it will always give me null value because of not checking "Enable AutoPostBack".and when i do this,it will refresh the page so this isnt what i wanted.

我该如何解决这个问题呢?

how can i solve this problem?

任何想法...

推荐答案

这听起来像你可能没有使用的UpdatePanel的功能正常。如果您在UpdatePanel设置更新当孩子触发事件,仅在UpdatePanel应该刷新,而不是整个页面。下面的code似乎表现类似于你正在寻找什么。当改变下拉,只有更新面板回发到服务器,当你刷新页面,就可以得到价值了会议。

It sounds like you may not be using the UpdatePanel feature properly. If you have the UpdatePanel set to update when children fire events, only the UpdatePanel should refresh, not the entire page. The code below seems to behave similar to what you are seeking. When changing the drop down, only the update panel posts back to the server and when you refresh the page, you can get the value out of the session.

ASPX code

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        Current Time: <asp:Label ID="lblTime" runat="server" /><br />
        Session Value: <asp:Label ID="lblSessionValue" runat="server" /><br />
        <br />
        <asp:UpdatePanel ID="upSetSession" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddlMyList" runat="server" 
                    onselectedindexchanged="ddlMyList_SelectedIndexChanged"
                    AutoPostBack="true">
                    <asp:ListItem>Select One</asp:ListItem>
                    <asp:ListItem>Maybe</asp:ListItem>
                    <asp:ListItem>Yes</asp:ListItem>
                </asp:DropDownList>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlMyList" 
                    EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
</form>

code背后

    protected void Page_Load(object sender, EventArgs e)
    {
        this.lblTime.Text = DateTime.Now.ToShortTimeString();
        if (Session["MyValue"] != null) 
            this.lblSessionValue.Text = Session["MyValue"].ToString();
    }

    protected void ddlMyList_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session.Remove("MyValue");
        Session.Add("MyValue", this.ddlMyList.SelectedValue);
    }

这篇关于DropDownList的中的UpdatePanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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