Can not access properties of controls of user control???

Discussion in 'ASP .Net Building Controls' started by chaoy@pacbell.net, Aug 24, 2003.

  1. Guest

    Hi,

    I have created a user control, and need to change the properties of
    controls on the user control. However, if the form of user control are
    not runat=server, I got error of "...is null or not a object". If I
    have the form runat=server, I got error of "A page can have only one
    server-side Form tag". For detail, please code below.

    It will be greatly appreciated if anyone can give me quick reply.

    Thanks.

    Charles

    <%@ Register TagPrefix="mintfact"
    Namespace="mintFact.webServerControls" Assembly="cMenu" %>
    <%@ Control Language="c#" AutoEventWireup="false"
    Codebehind="WebUserControl1.ascx.cs"
    Inherits="JavaInUserControl.WebUserControl1"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <form id="form11" name="form11" runat =server>

    <P>
    <TABLE id="Table1" style="HEIGHT: 27px" cellSpacing="1"
    cellPadding="1" width="700" align="center" border="1">
    <TR>
    <TD align="middle">
    <P align="center"><Center>
    <mintfact:cMenu id="CMenu1" runat="server"
    MenuData="MenuData.xml" TopMenuIsHorizontal="True"
    MenuWidth="102"></mintfact:cMenu></Center>
    <P></P>
    </TD>
    </TR>
    </TABLE>
    </P>
    <P>
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
    <P></P>
    <DIV style="DISPLAY: inline; WIDTH: 153px; HEIGHT: 24px"
    ms_positioning="FlowLayout">above
    is server control</DIV>
    <P></P>
    <DIV style="DISPLAY: inline; WIDTH: 153px; HEIGHT: 19px"
    ms_positioning="FlowLayout">below
    is a htmp control</DIV>
    <P><INPUT id="hdnWidth" type="hidden" name="hdnWidth"
    runat="server"></P>
    <script language="javascript">
    debugger;
    var iWidth;
    iWidth = window.screen.width;
    iWidth = (iWidth - 700)/2-10;
    document.form11.elements
    //document.form11.TextBox1.value = iWidth;
    document.form11.hdnWidth.value = iWidth;
    //if (iWidth != 800)
    //document.all.CMenu1.Left = 60;

    //document.all.hdnWidth.value = window.screen.width
    //document.all.item("servercontrol").value=sWidth;
    sWidth = "try";
    </script>
    </form>
     
    , Aug 24, 2003
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    >
    > I have created a user control, and need to change the properties of
    > controls on the user control.


    ASP.NET is based on OO principals. One of the most basic of the OO
    principals is "encapsulation". This means that what's inside of the User
    Control is concern of the User Control alone, unless it chooses to expose
    its internals.

    If you have a control, say, "Btn1" within your user control, and if it's
    really necessary that arbitrary properties of that control be accessible
    from outside of the user control, then the user control should have a
    property to expose that control:

    public Button ButtonOne
    {
    get {return Btn1;}
    }

    The user of an instance of the user control (call it UserControl1) could
    then access UserControl1.ButtonOne.Text, for instance.

    If you only need a few properties of the inner controls to be visible, then
    make only those properties visible:

    public string ButtonOneText
    {
    get {return Btn1.Text;}
    set {Btn1.Text = value;}
    }

    public Color ButtonOneForeColor
    {
    get {return Btn1.ForeColor;}
    set {Btn1.ForeColor = value;}
    }

    Hiding the details of the inner controls allows you the freedom to change
    how they are implemented in the future. For instance, if only certain
    properties are exposed, you could decide some day to change Btn1 to be a
    LinkButton or ImageButton, and the callers of your user control would never
    need to know.
    --
    John Saunders
    Internet Engineer
     
    John Saunders, Aug 24, 2003
    #2
    1. Advertising

  3. Charles Liang, Aug 25, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YWJqb3Jr?=
    Replies:
    1
    Views:
    3,863
    Jeffrey Palermo
    May 5, 2004
  2. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    Can't access databound dropdownlist properties in user control

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Nov 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    477
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Nov 8, 2005
  3. Max2006
    Replies:
    2
    Views:
    530
    Max2006
    Jul 13, 2007
  4. Faizan Ahmed
    Replies:
    1
    Views:
    306
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    384
    John Saunders
    Jan 4, 2005
Loading...

Share This Page