Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
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:

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

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


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.


XML
<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>
Posted
Updated 28-Apr-11 8:21am
v3

1 solution

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 :)
 
Share this answer
 
v2
Comments
Nish Nishant 28-Apr-11 12:03pm    
Decent response. My vote of 5!
Albin Abel 28-Apr-11 12:04pm    
Thanks Nishant
wooga111 28-Apr-11 12:12pm    
I am not familiar with personalization. I will take a look to see if it is something I can use. If you have any good reference material I would appreciate it. Otherwise it's google to the rescue :)
Albin Abel 28-Apr-11 12:37pm    
Here are few links http://msdn.microsoft.com/en-us/magazine/cc163724.aspx

http://www.tutorialized.com/view/tutorial/Personalization/10366

This one compares session and personalization http://www.developer.com/net/asp/article.php/3520226/ASPNET-20-Profile-Simple-User-Personalization-for-Your-Web-Apps.htm

wooga111 28-Apr-11 13:22pm    
I really like how personalization works but I am not sure it will solve my problem. I will still want to clear out the saved DataTable on an initial object mode - this is only a problem on insert with the formview. I can't clear the information because !IsPostBack is false for things other than the initial page load. (it fires during page button clicks). The saved DataTable needs to be cleared only once at the beginning. Any code I write had it clearing at every event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900