More in this section

Forums / Developing with Sitefinity / Using SessionDataSource programmatically

Using SessionDataSource programmatically

5 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    24 Apr 2009
    Link to this post

    Hello Sitefinity Team

    I want to use the sessiondatasource in code behind as described below. When the uxOrderItemsSessionDataSource.Insert() is executed I get the error 'Object Reference not set' caused by IDictionary values = null in the function ExecuteInsert (row 368 SessionDataSource.cs).
    When I use a SQLDataSource instead of the SessionDataSource everything works fine.

    Have you an idea how I can use it with the sessiondatasource?

    Regards
    Luc

     

    Partial

     

    Class test
    Inherits System.Web.UI.Page

     

     

    Protected Sub lbtnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)Try
    Dim lbtnProductPrice As LinkButton = DirectCast(sender, LinkButton)uxOrderItemsSessionDataSource.InsertParameters("ProductID").DefaultValue = 1
    uxOrderItemsSessionDataSource.InsertParameters(
    "SessionID").DefaultValue = Session.SessionID
    uxOrderItemsSessionDataSource.Insert()
    Catch ex As Exception
    End Try
    End Sub

     

     

     

    Protected Sub lbtnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnDelete.Click
    Try
    uxOrderItemsSessionDataSource.Delete()
    Catch ex As Exception
    End Try
    End Sub

     

    End

     

    Class

     

  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    29 Apr 2009
    Link to this post
    Hello Luc Baeten,

    As far as I understand, you are using the SessionDataSource that is used in the RadControls demos for testing purposes. The code you've provided creates a page class that directly inherits from an ASP.NET page, so Sitefinity has little to do with this, because the CMS has its own cms pages and doesn't work with any other types of pages.
    If you provide more details on where you are using this in your project and how we can reproduce it locally we'd be glad to help.

    Regards,
    Slavo
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    30 Apr 2009
    Link to this post

    Hello Stavo

    I used the sessiondatasource in a user control. Because of the error I created a tes page to show you how to reproduce the error. Here the code of the test page.

    Kind regards
    Luc

    <%

    @ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
    <%
    @ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
    <%
    @ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head runat="server">
    <title></title>
    </
    head>
    <
    body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <telerik:RadGrid AutoGenerateColumns="false" ID="uxBasketRadGrid" EnableEmbeddedSkins="false"
    Skin="Products" ShowHeader="false" DataSourceID="uxOrderItemsSessionDataSource"
    ShowFooter="True" runat="server" GridLines="None" Width="180">
    <MasterTableView>
    <Columns>
    <telerik:GridBoundColumn DataField="ProductID" UniqueName="ProductID">
    </telerik:GridBoundColumn>
    </Columns></MasterTableView>
    <ClientSettings AllowDragToGroup="true" EnableRowHoverStyle="true" />
    </telerik:RadGrid>

    <sds:sessiondatasource id="uxOrderItemsSessionDataSource" runat="server" sessionkey="OrderItems"
    oldvaluesparameterformatstring="original_{0}" displaywarning="false" connectionstring="<%$ ConnectionStrings:EnvioAdomicilioOrdering %>"
    selectcommand="SELECT * FROM OrderItemsSession WHERE SessionID=@SessionID" deletecommand="DELETE FROM OrderItemsSession WHERE SessionID=@SessionID" InsertCommand="INSERT INTO [OrderItemsSession] ([ProductID],[SessionID]) VALUES (@ProductID, @SessionID)"
    conflictdetection="CompareAllValues" PrimaryKeyFields="OrderItemID" ProviderName="System.Data.SqlClient">
    <InsertParameters>
    <asp:Parameter Name="ProductID" Type="Int32" />
    <asp:Parameter Name="SessionID" Type="String" />
    </InsertParameters>
    <DeleteParameters>
    <asp:SessionParameter
    Name="SessionID"
    SessionField="SessionID"
    DefaultValue="5" />
    </DeleteParameters>
    <SelectParameters>
    <asp:SessionParameter
    Name="SessionID"
    SessionField="SessionID"
    DefaultValue="5" />
    </SelectParameters>
    </sds:sessiondatasource>
    <asp:LinkButton ID="lbtnAdd" runat="server" CommandArgument='3'
    OnClick="lbtnAdd_Click">Add</asp:LinkButton>
    <asp:LinkButton ID="lbtnDelete" runat="server" CommandArgument='3'
    OnClick="lbtnDelete_Click">Delete</asp:LinkButton>
    </div>
    </form>
    </
    body>
    </
    html>

     

  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    07 May 2009
    Link to this post
    Hi Luc Baeten,

    Thank you for reporting this issue. Seems, there is a missing check for NULL of the values parameter in the SessionDataSource. Please try to fix the problem by adding it:
    if (values != null
        foreach (DictionaryEntry newValue in values) 
        { 
            newRow[(string)newValue.Key] = newValue.Value != null ? newValue.Value : DBNull.Value; 
        } 
     

    We have also attached the updated file.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    08 May 2009
    Link to this post
    Hello Vlad

    Thank you for your response. I will try it and let you know.

    Regards
    Luc
Register for webinar
5 posts, 0 answered