Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2006

Tip: Looking for answers? Try searching our database.

User control not seen on code beside (behind) page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
petro - 22 Sep 2006 23:28 GMT
Can someone shed some light on how to get this user control to work?
I created a simple user control with several properties (I want to access
these properties server side on another web form (a web control consumer
page)).  Then I drug the user control on to the web form where I wanted to
use it.  In the design view I see the web control on the web form and I can
also access it's properties on the client side. But when I try to get to the
control from the code beside page (ie. UserControlConsumerPage.cs)  I do not
see a reference to the control in intellisense.  Here is my user control code
from the UserControl.ascx:

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="ContractInfo.ascx.cs" Inherits="ContractInfo" %>
<table style="width: 754px">
   <tr>
       <td style="width: 314px">
           Contact Information</td>
       <td>
       </td>
   </tr>
   <tr>
       <td style="width: 314px">
           Contract #</td>
       <td>
           <asp:Label ID="lblContract" runat="server" Text="Label"
Width="378px"></asp:Label></td>
   </tr>
   <tr>
       <td style="width: 314px">
           Agency</td>
       <td>
           <asp:Label ID="lblAgency" runat="server" Text="Label"
Width="378px"></asp:Label></td>
   </tr>
   <tr>
       <td style="width: 314px">
           Program</td>
       <td>
           <asp:Label ID="lblProgram" runat="server" Text="Label"
Width="378px"></asp:Label></td>
   </tr>
   <tr>
       <td style="width: 314px; height: 20px">
           Report Quarter</td>
       <td style="height: 20px">
           <asp:Label ID="lblReportQuarter" runat="server" Text="Label"
Width="378px"></asp:Label></td>
   </tr>
</table>

HERE IS the code from the UserControl.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ContractInfo : System.Web.UI.UserControl
{
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!this.lblReportQuarter.Visible)
           Response.Write("<script type='text/javascript'>var varRQ =
'';</script>");
   }

   public string Contract
   {
       get
       {
           return this.lblContract.Text;
       }
       set
       {
           this.lblContract.Text = Server.HtmlEncode(value);
       }
   }

   public string Agency
   {
       get
       {
           return this.lblAgency.Text;
       }
       set
       {
           this.lblAgency.Text = Server.HtmlEncode(value);
       }
   }

   public string Program
   {
       get
       {
           return this.lblProgram.Text;
       }
       set
       {
           this.lblProgram.Text = Server.HtmlEncode(value);
       }
   }

   public string ReportQuarter
   {
       get
       {
           return this.lblReportQuarter.Text;
       }
       set
       {
           this.lblReportQuarter.Text = Server.HtmlEncode(value);
       }
   }

   public Boolean ReportQuarterVisible
   {
       set
       {
           this.lblReportQuarter.Visible = value;
       }
   }

}

THIS IS the code from the UserControlConsumerPage.ascx that I want to use
the control:

<%@ Page Language="C#" MasterPageFile="~/pmAgency/masAgency.master"
AutoEventWireup="true" CodeFile="wfNarrative.aspx.cs" Inherits="wfNarrative"
Title="Untitled Page" %>

<%@ Register Src="../ContractInfo.ascx" TagName="ContractInfo"
TagPrefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">

       <asp:Panel ID="pnlNarr" runat="server" Height="459px" Width="801px"
style="z-index: 100; left: 152px; position: absolute; top: 67px"
BackColor="White">
           <table id="tblOutNarr" style="width: 800px; height: 311px">
               <tr>
                   <td style="height: 121px">
                       
                       <uc1:ContractInfo ID="ContractInfo1" runat="server" />
                       </td>
               </tr>
               <tr>
Gaurav Vaish (www.EduJiniOnline.com) - 24 Sep 2006 06:45 GMT
> control from the code beside page (ie. UserControlConsumerPage.cs)  I do
> not
> see a reference to the control in intellisense.  Here is my user control
> code
> from the UserControl.ascx:

So, is the problem with intellisense?
Ensure that you have given an appropriate ID to the control.

I don't see you using "ContractInfo1" anywhere... may be because the code
was clipped.

Signature

Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------

petro - 25 Sep 2006 16:47 GMT
I found the problem.  It was not with the user control at all.  I had copied
and pasted the page dcirective from one page to other pages and did not
change the codefile and inherits references. Once I fixed that the user
control worked as expected.  Thanks for your reply.

> > control from the code beside page (ie. UserControlConsumerPage.cs)  I do
> > not
[quoted text clipped - 7 lines]
> I don't see you using "ContractInfo1" anywhere... may be because the code
> was clipped.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.