首次加载页面上的会话信息. [英] Session Information on Page First load.

查看:125
本文介绍了首次加载页面上的会话信息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是我的情况:

我正在使用VS2010,并且具有ASP.NET Web应用程序.在我的页面上,我正在使用WebUserControl,该WebUserControl使用modelpopupextender允许用户从列表中选择联系人.所有这些都包含在asp.net formview中.

用户选择了某些联系人后,他们单击提交"按钮,然后他们的选择进入一个ListView,该ListView绑定到我存储在会话中的DataTable.

以上所有方法都很棒.


问题在于,当用户将带有联系人的对象插入时,DataTable信息会保留,如果再次插入,则先前的对象会在不应该出现的情况下重新出现.插入后我无法清除会话,以防用户关闭页面而不插入而另一个打开保留了该会话或另一个屏幕重新加载了数据.

我要执行的操作如下:

Hello All,

Here is my scenario:

I am using VS2010 and have a ASP.NET web application. On my page I am using a WebUserControl that uses a modelpopupextender to allow a user to select contacts from a list. All of this is contained in a asp.net formview.

After a user selects some contacts they click the submit button and their selection goes to a ListView that is bound to a DataTable that I store in the session.

All of the above works great.


The problem is that when the user inserts the object with the contacts the DataTable information is kept and if you do another insert the previous objects re-appear when they should not. I can''t clear the session after the insert incase the user closes the page without inserting and another open retains the session or another screen re-loads the data.

What I want to do is the following:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
                ClearSessionDataTable();

            if (AccountID == 0)
            {
                this.fvAccount.ChangeMode(FormViewMode.Insert);
            }
        }



但是……负载表明,无论我单击页面上的哪个按钮,它都不是回发.因此,每次事件时都会清除会话信息.同样,在回发之间不保留Viewstate.

我需要的是一种确定页面的初始负载的方法,这样我就可以清除会话.



我需要一种更好的方法来临时存储动态数量的信息,而不将其提交给数据库,直到用户单击保存.


我希望其中一些是有道理的,
谢谢,
亚伦


更新:

事实证明,我的Page_load每回发一次都触发超过1次.我已经缩小了罪魁祸首的范围,但是不知道为什么会造成这种情况. -当我从WebUserControl中删除以下内容时,页面加载问题已修复.仅供参考-下面的代码创建一个弹出窗口,该弹出窗口显示一个复选框列表,允许用户选择多个项目-它与javascript非常相关.




But...... the load says that it is not a postback no matter what button I click on the page. So the session information is cleared at every event. Also the Viewstate is not kept between postbacks.

What I need is a way to determine the initial load of the page so I can clear the session.

OR

I need a better way to temporary store a dynamic amount of information without submitting them to the database until the user clicks saves.


I hope some of this makes sense,
Thanks,
Aaron


UPDATE:

It turns out that my Page_load is fireing more than 1 time per post back. I have it narrowed down the the culprit but am not sure why it is causeing this. - When I take the below out of my WebUserControl the page load problem is fixed. FYI - the below code creates a pop-up that displays a list of checkboxes which allows a user to select more than one item - it it pretty involved with javascript.


<asp:ImageButton ID="btnFilterBUs" runat="server"

    CssClass="MultiSelect" />
<ajax:ModalPopupExtender ID="btnFilterBUs_ModalPopupExtender"

    runat="server"

    OkControlID="btnOkBUs" PopupControlID="dialogBUs"

    TargetControlID="btnFilterBUs">
</ajax:ModalPopupExtender>
<asp:Panel ID="dialogBUs" runat="server" CssClass="modPnl" style="display:none;">
    <b>Select Business Use Types To Display:</b><br />
    <br />
    <asp:LinkButton ID="btnOkBUs" runat="server" style="float:right" >OK</asp:LinkButton>
    <a href="javascript:clearCheckboxes('<%=lblSelectedBUs.ClientID %>', '<%=lblCheckedBUs.ClientID %>', BusinessUseTypeCBA);" style="float:left">Clear Selection</a>
    <br />
    <br />
    <div class="modDiv">
        <asp:LinqDataSource ID="BUsDataSource" runat="server"

            ContextTypeName="US.QBE.BAR.Business.BARDataClassesDataContext"

            TableName="AccountBusinessUseTypes"

            Select="new (AccountBusinessUseTypeID, AccountBusinessUseTypeValue)" OrderBy="AccountBusinessUseTypeValue">
        </asp:LinqDataSource>
        <asp:CheckBoxList ID="cblBUs" runat="server"

            DataSourceID="BUsDataSource" DataTextField="AccountBusinessUseTypeValue"

            DataValueField="AccountBusinessUseTypeID"

            OnPreRender="BUs_PreRender">
        </asp:CheckBoxList>
    </div>
    <hr />
    <br />
    <b>Business Use Types:</b>
    <br />
    <br />
    <asp:Label ID="lblCheckedBUs" runat="server" Text="None"></asp:Label>
    <br />
</asp:Panel>
<asp:Label ID="lblSelectedBUs" runat="server"

     CssClass="modLblSelected" Text="None">
</asp:Label>
<h5><asp:Label runat="server" Text="*" /></h5>

推荐答案

如果您了解Personalization,则可以很好地存储和检索特定于用户的信息,而不是会话.但是,这些对象需要可序列化.这是另一种建议.如果您已经了解.Net中的个性化设置,那么我就不需要再写了:)
If you know about Personalization you can very well to store and retrieve user specific informations instead of session. However those objects needs to be serializable. This is an alternate suggestion. If you already know about personalization in .Net i don''t need to write more on it :)


这篇关于首次加载页面上的会话信息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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