Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Can not access properties of controls of user control???

Reply
Thread Tools

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

 
 
chaoy@pacbell.net
Guest
Posts: n/a
 
      08-24-2003
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>
 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      08-24-2003
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Charles Liang
Guest
Posts: n/a
 
      08-25-2003


I got cMenu from the address below.

http://www.c-sharpcorner.com/Code/20...NetMenu1.1.asp

It works just fine but centering.

Thanks.

Charles

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why the properties of web user controls which inherted from my custom base UI controls MISSED? ABC ASP .Net Web Controls 0 11-21-2005 04:08 AM
Why the properties of web user controls which inherted from my custom base UI controls MISSED? ABC ASP .Net Building Controls 0 11-21-2005 04:08 AM
Why the properties of web user controls which inherted from my custom base UI controls missed? ABC ASP .Net 0 11-21-2005 04:08 AM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Building Controls 1 01-04-2005 04:09 PM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Web Controls 1 01-04-2005 04:09 PM



Advertisments