User control not seen on code beside (behind) page

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default User control not seen on code beside (behind) page

    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>


    petro Guest

  2. Similar Questions and Discussions

    1. user control problem access value from user control to a page
      Thanks a lot for paying attention to my problem , i tell u the problem i have a main form in which i gave a login label that points to a...
    2. code :::::USer control for menu
      I HAVE WRITTEN THE CODE FOR USER CONTROL MENU BUT I AM UNABLE TO SEE IT IN DESIGN VIEW WHY WHERE WAS I WRONG. THE CODE IS AS FOLLOWS: <%@...
    3. Custom Server Control works on page but not User Control...why?
      I'm developing the DevEdit.NET server control (an online HTML editor - www.devedit.com) but there's an extremely bizarre bug. The control runs fine...
    4. Page Load fired 3 times Web user control is embedded in a custom control
      Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,...
    5. accessing page variable from user control code behind
      Hi all, I have a aspx page that inherits from a cs class which is common for all pages in my application. In that cs file, I define some...
  3. #2

    Default Re: User control not seen on code beside (behind) page

    > 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.


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


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

  4. #3

    Default Re: User control not seen on code beside (behind) page

    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.

    "Gaurav Vaish (www.EduJiniOnline.com)" wrote:
    > > 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.
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | [url]http://www.mastergaurav.com[/url]
    > [url]http://www.edujinionline.com[/url]
    > [url]http://articles.edujinionline.com/webservices[/url]
    > -------------------
    >
    >
    >
    petro Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139