Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Control Error

Status
Not open for further replies.

ccshadow

Programmer
Jan 29, 2004
33
US
I've created a user control page containing a third-party grid. The code works fine when the grid is embedded in a regular ASP.NET page. However, errors are being thrown once I add the same grid as an .ascx control to a page. This is the first time I've created a user control so I'm hoping there's something really obvious wrong.

.ascx Code-behind:
Code:
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Page
Imports System.Data
Imports System.Data.SqlClient
Imports Obout.Grid

Partial Class Goals
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            GetGoals(sender, e)
        End If

    End Sub

    Sub GetGoals(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim conn As New SqlConnection("Server=WACBLSQL03;Database=WACommissions;User ID=WACommWeb;Password=123;Trusted_Connection=False")
        Dim cmd As New SqlCommand("stp_GetAgentGoals", conn)
        cmd.CommandType = CommandType.StoredProcedure

        Try
            conn.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader
            Trace.Warn(reader.HasRows)
            grdGoals.DataSource = reader
            grdGoals.DataBind()
            reader.Close()
        Catch ex As Exception
            Trace.Warn(ex.ToString)
        Finally
            conn.Dispose()
        End Try

    End Sub

.ascx:
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Goals.ascx.vb" Inherits="Goals" %>
<%@ import namespace="Obout.Grid" %>
<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="obout" %>

<obout:Grid runat="server" id="grdGoals" FolderStyle="/obout/style_8" AutoGenerateColumns="False" 
EnableRecordHover="true" AllowAddingRecords="False" AllowRecordSelection="False" CallbackMode="true" Serialize="true" 
OnRebind="GetGoals" OnUpdateCommand="UpdateGoals" AllowMultiRecordSelection="False" AllowGrouping="True" GroupBy="name,SDTE" ShowCollapsedGroups="True" PageSize="100">
    <Columns>
    <obout:Column Width="100px" HeaderAlign="center" DataField="name" ReadOnly="True" HeaderText="Name" Index="0"></obout:Column>
     <obout:Column Width="0px" HeaderAlign="center" Visible="False" DataField="HRID" ReadOnly="True" HeaderText="HRID" Index="1"></obout:Column>
     <obout:Column Width="80px" HeaderAlign="center" DataField="SDTE" ReadOnly="True" HeaderText="Start Date" Index="2"></obout:Column>
     <obout:Column Width="80px" HeaderAlign="center" DataField="EDTE" ReadOnly="True" HeaderText="End Date" Index="3"></obout:Column>
     <obout:Column Width="95px" HeaderAlign="center" DataField="GTOP" ReadOnly="True" HeaderText="GTOP" Index="4"></obout:Column>
     <obout:Column Width="60px" HeaderAlign="center" DataField="VID" HeaderText="VID" Index="5"></obout:Column>
     <obout:Column Width="60px" HeaderAlign="center" DataField="LIM" HeaderText="LIM" Index="6"></obout:Column>
     <obout:Column Width="60px" HeaderAlign="center" DataField="BAS" HeaderText="BAS" Index="7"></obout:Column>
     <obout:Column Width="60px" HeaderAlign="center" DataField="ENH" HeaderText="ENH" Index="8"></obout:Column>
</Columns>
    </obout:Grid>

.aspx:
Code:
<%@ Page Language="VB" MasterPageFile="~/_Lib/Site.master" StyleSheetTheme="Site" AutoEventWireup="false" CodeFile="Home.aspx.vb" Inherits="Home" title="Home" %>
<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="obout" %>

<%@ Register Src="Goals.ascx" TagName="Goals" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    &nbsp;<uc1:Goals id="grdGoals" runat="server"></uc1:Goals>
</asp:Content>
 
I forgot to include the text of the error... It kinda seems like it's not able to access the dll for the 3rd party grid. ?

Code:
Compiler Error Message: BC30456: 'DataSource' is not a member of 'ASP.goals_ascx'.

Source Error:
 
Line 27:             Dim reader As SqlDataReader = cmd.ExecuteReader
Line 28:             Trace.Warn(reader.HasRows)
Line 29:             grdGoals.DataSource = reader
Line 30:             grdGoals.DataBind()
Line 31:             reader.Close()
 
You are trying to set the DataSource property of the user control, not the actual control that you've added to the user control (you've just happened to name them both "grdGoals").

You will either have to expose a Public Property in the user control and set the DataSource of the Grid through that, or get a reference directly to the Grid by using the FindCOntrol method of the user control.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks for the direction.

This user control will ultimately be embedded in a SharePoint site using the SmartPart. Given this, is one method preferred over another?

If it gets added to SharePoint, I wouldn't necessarily know the name used in order to use FindControl. Wouldn't I need to use the grid name used in the page and not the .ascx file? I'm not even sure how to go about exposing a Public Property in the grid.
 
Using FindControl is a lot easier. And you'd use the name you give it in your ASCX to find it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top