Problems with asp:ObjectDataSource

  1. #1

    Problems with asp:ObjectDataSource

    *Hi, I'm having problems with the SelectMethod.*The select method is a non static method of the Code behindI need to access Coolite controls and Session variables, but all of them are NULL


    I'm passing some information using SessionParameter but it's not a good solution, I need some other context information too


    We also need to add tooltips for each item of the Select query, I thought it could be posible using AddScript("new Tooltip...") on the ImageView but now it's imposible because all the controls are NULL


    Thanks

  2. #2

    RE: Problems with asp:ObjectDataSource

    Hi,

    Does this problem occur only with Coolite controls or with ASP.NET also?
    Please post code which shows the problem
    *
  3. #3

    RE: Problems with asp:ObjectDataSource

    Thanks for the quick response!


    The problem occurs with Coolite controls and with ASP.NET too!



    Inside "ObjectDataSource_GetData" method you can find the problematic code. Thanks


    Here is Default.aspx


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!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">
    ** * * *<ext:ScriptManager ID="ScriptManager" runat="server"/> * *
    ** * * *
    ** * * *<asp:ObjectDataSource*
    ** * * * * *ID="ObjectDataSource"*
    ** * * * * *runat="server"*
    ** * * * * *OnSelected="ObjectDataSource_Selected"
    ** * * * * *SelectMethod="ObjectDataSource_GetData"
    ** * * * * *TypeName="WebApplication1._Default">
    ** * * * * *<SelectParameters>
    ** * * * * * * *<asp:SessionParameter Name="categoryId" SessionField="CategoryId" /> * * * *
    ** * * * * * * *<asp:Parameter Name="start" Type="Int32" />
    ** * * * * * * *<asp:Parameter Name="limit" Type="Int32" />
    ** * * * * * * *<asp:Parameter Name="sort" />
    ** * * * * * * *<asp:Parameter Name="dir" />
    ** * * * * * * *<asp:Parameter Name="count" Direction="Output" Type="Int32" /> * * * * * * * *
    ** * * * * *</SelectParameters> **
    ** * * *</asp:ObjectDataSource>
    ** * * * * * * *
    ** * * *<ext:Store*
    ** * * * * *ID="Store"
    ** * * * * *runat="server"
    ** * * * * *OnRefreshData="Store_Refresh"
    ** * * * * *RemoteSort="true"
    ** * * * * *DataSourceID="ObjectDataSource" * * * * * *
    ** * * * * *AutoLoad="false">
    ** * * * * *<Reader>
    ** * * * * * * *<ext:JsonReader ReaderID="Id">
    ** * * * * * * * * *<Fields>
    ** * * * * * * * * * * *<ext:RecordField Name="Id" />
    ** * * * * * * * * * * *<ext:RecordField Name="Name" /> * * * * * * * * * * * *
    ** * * * * * * * * *</Fields>
    ** * * * * * * *</ext:JsonReader>
    ** * * * * *</Reader>
    ** * * * * *<Proxy>
    ** * * * * * * *<ext:DataSourceProxy></ext:DataSourceProxy>
    ** * * * * *</Proxy> * * * * * *
    ** * * *</ext:Store>
    ** * * *
    ** * * *<ext:Panel ID="Panel" runat="server">
    ** * * * * *<Body>
    ** * * * * * * *<ext:ContainerLayout ID="FitLayout3" runat="server"> * * * * * * * * * * * *
    ** * * * * * * * * *<ext:DataView runat="server"*
    ** * * * * * * * * * * *ID="ImageView"
    ** * * * * * * * * * * *Name="ImageView"
    ** * * * * * * * * * * *OverClass="x-view-over"
    ** * * * * * * * * * * *StoreID="Store"
    ** * * * * * * * * * * *MultiSelect="true"
    ** * * * * * * * * * * *ItemSelector="div.thumb-wrap" * * * * * * * * * * * * * *
    ** * * * * * * * * * * *EmptyText="No items to display">
    ** * * * * * * * * * * *<Template ID="Template1" runat="server" style="float:left">
    ** * * * * * * * * * * * * *<tpl for=".">
    ** * * * * * * * * * * * * * * **<div id={Id}>
    ** * * * * * * * * * * * * * * * * *{Name}
    ** * * * * * * * * * * * * * * * 
     * * * * * * * * * * * * * * * * * * * *** * * * * * * * * * * * * * * * * * **
    ** * * * * * * * * * * * * *</tpl>
    ** * * * * * * * * * * * * *<div class="x-clear">
     * * * * * * * * * * * * * *
    ** * * * * * * * * * * *</Template>
    ** * * * * * * * * *</ext:DataView>
    ** * * * * * * *</ext:ContainerLayout>
    ** * * * * *</Body>
    ** * * *</ext:Panel> * *
    ** *</form>
    </body>
    </html>
    
    
    /////////////////////////////////////////////////
    //////////Default.aspx.cs////////////////////
    /////////////////////////////////////////////////
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace WebApplication1
    {
    ** *public partial class _Default : System.Web.UI.Page
    ** *{
    ** * * *protected void Page_Load(object sender, EventArgs e)
    ** * * *{
    
    
    ** * * *}
    
    
    ** * * *public List<Item> ObjectDataSource_GetData(Guid categoryId, int start, int limit, string sort, string dir, out int count)
    ** * * *{
    ** * * * * *List<Item> Items = null; //Get All items
    ** * * * * *//StringBuilder tooltipScript = new StringBuilder();
    ** * * * * *//foreach (Item itemInfo in Items)
    ** * * * * *//{ * * * * * *
    ** * * * * *// * *tooltipScript.Append("var " + itemInfo.Name + "tooltip = new Ext.ToolTip({"
    ** * * * * *// * * * * * * * * * * * * * * * * *+ " * target: '" + itemInfo.Id.ToString() + "',"
    ** * * * * *// * * * * * * * * * * * * * * * * *+ " * html: '" + GetTooltip(itemInfo) + "'"
    ** * * * * *// * * * * * * * * * * * * * * * * *+ "});");
    ** * * * * *//}
    ** * * * * *//this.ImageView.AddScript(tooltipScript) //ImageView and Session are NULL
    ** * * * * *return Items;
    ** * * *}
    
    
    ** * * *protected void ObjectDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    ** * * *{
    ** * * * * *(this.Store.Proxy[0] as DataSourceProxy).TotalCount = (int)e.OutputParameters["count"];
    ** * * *}
    ** *}
    }


    Thanks in advance!

  4. #4

    RE: Problems with asp:ObjectDataSource

    Hi,

    I think that ObjectDataSource create instance of selected type. Therefore you will have instance another page which was created by ObjectDataSource (therefore it can initialized incorrect) and*ObjectDataSource_GetData called other instanse (not requested page).


    Try to add ObjectCreating handler
    protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {  
      e.ObjectInstance = this;
    }

    It is not Coolite Toolkit problem. Just you incorrect use ObjectDataSource. It is bad idea to mix select data logic with changing UI controls.




  5. #5

    RE: Problems with asp:ObjectDataSource

    Hi,


    You can found interesting this article
    http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=368*


  6. #6

    RE: Problems with asp:ObjectDataSource

    *Great!

    Thanks for the article! It makes me see the problem clever!


    I can't still use the addScript (it keeps waiting on Loading) but I can use Session.


    Many thanks!

Similar Threads

  1. ObjectDataSource and MVC3
    By Therruco in forum 2.x Help
    Replies: 0
    Last Post: May 25, 2012, 3:23 PM
  2. [CLOSED] GridPanel update problems with ObjectDataSource
    By jasonl in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 17, 2011, 10:59 AM
  3. Can I use a Form with an ObjectDataSource?
    By FlorMariaF in forum 1.x Help
    Replies: 0
    Last Post: Jan 19, 2010, 1:46 PM
  4. [CLOSED] Problems with asp:ObjectDataSource
    By antonyn in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Feb 02, 2009, 10:50 AM
  5. GridPanel + ObjectDataSource
    By Chelonian in forum 1.x Help
    Replies: 2
    Last Post: Sep 05, 2008, 7:18 AM

Posting Permissions