473,748 Members | 7,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User control accessing outside control

I am trying to put together a user control (.ascx).

Can you access an outside control from it?

My control:

login2.ascx
*************** *************** *************** *************** ****
<script runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
if not IsPostBack
myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baselin e">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="Singl eLine" Columns="25"
runat="server" />
<asp:RequiredFi eldValidator
ControlToValida te="UserName"
Text="User Name Required"
runat="server" />
</td>
</tr>
</table>
*************** *************** *************** *************** ****

I get an error on access "mybody" as:

Name 'myBody' is not declared.

My aspx file looks essentially like:
*************** *************** *************** *************** **
<html>
<%@ Register TagPrefix="fts" TagName="Login" Src="login2.asc x" %>
<head>
<title>:: Staffing Workshop ::</title>
</head>

<body id="myBody" runat="server">
<form runat="server">
<fts:Login runat="server"/>
</form>
</body>
</html>
*************** *************** *************** *************** **

If I comment the line:

' myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")

it works fine.

Is there a way to access this outside body tag from my control?

Thanks,

Tom
May 19 '06 #1
3 1771
1) Expose mybody as property of you user control so parent form can set
reference of mybody into it.

2) Set the UserControl.myb ody = this.mybody in the parent page load.Then
call usercontrol load, it will work.

Please give feedback of this post.

"tshad" wrote:
I am trying to put together a user control (.ascx).

Can you access an outside control from it?

My control:

login2.ascx
*************** *************** *************** *************** ****
<script runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
if not IsPostBack
myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baselin e">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="Singl eLine" Columns="25"
runat="server" />
<asp:RequiredFi eldValidator
ControlToValida te="UserName"
Text="User Name Required"
runat="server" />
</td>
</tr>
</table>
*************** *************** *************** *************** ****

I get an error on access "mybody" as:

Name 'myBody' is not declared.

My aspx file looks essentially like:
*************** *************** *************** *************** **
<html>
<%@ Register TagPrefix="fts" TagName="Login" Src="login2.asc x" %>
<head>
<title>:: Staffing Workshop ::</title>
</head>

<body id="myBody" runat="server">
<form runat="server">
<fts:Login runat="server"/>
</form>
</body>
</html>
*************** *************** *************** *************** **

If I comment the line:

' myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")

it works fine.

Is there a way to access this outside body tag from my control?

Thanks,

Tom

May 19 '06 #2
"Altaf Al-Amin Najwani" <al**********@g mail.com> wrote in message
news:33******** *************** ***********@mic rosoft.com...
1) Expose mybody as property of you user control so parent form can set
reference of mybody into it.
How would I do that?

The problem is that it can't reference it - how do I make it a property in
the user control?

2) Set the UserControl.myb ody = this.mybody in the parent page load.Then
call usercontrol load, it will work.
That would work.

I just wanted to find out how to access properties of the parent page from a
user control. This would obviously have to be looked at closely, but I am
trying to use my user controls on different parent pages that would all have
the same objects, but would be laid out differently.

Thanks,

Tom
Please give feedback of this post.

"tshad" wrote:
I am trying to put together a user control (.ascx).

Can you access an outside control from it?

My control:

login2.ascx
*************** *************** *************** *************** ****
<script runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
if not IsPostBack
myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baselin e">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="Singl eLine" Columns="25"
runat="server" />
<asp:RequiredFi eldValidator
ControlToValida te="UserName"
Text="User Name Required"
runat="server" />
</td>
</tr>
</table>
*************** *************** *************** *************** ****

I get an error on access "mybody" as:

Name 'myBody' is not declared.

My aspx file looks essentially like:
*************** *************** *************** *************** **
<html>
<%@ Register TagPrefix="fts" TagName="Login" Src="login2.asc x" %>
<head>
<title>:: Staffing Workshop ::</title>
</head>

<body id="myBody" runat="server">
<form runat="server">
<fts:Login runat="server"/>
</form>
</body>
</html>
*************** *************** *************** *************** **

If I comment the line:

'
myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")

it works fine.

Is there a way to access this outside body tag from my control?

Thanks,

Tom

May 19 '06 #3
Also, in this case I want to place the focus on my first textbox on initial
load of the logon page.

Normally, in my Page_Load of the page, I set the myBody attribute to set
this. I could still do this from the login page, but I would like to do
this from the control as I want to dynamically load this control.

Thanks,

Tom
"tshad" <ts**********@f tsolutions.com> wrote in message
news:en******** ******@TK2MSFTN GP04.phx.gbl...
"Altaf Al-Amin Najwani" <al**********@g mail.com> wrote in message
news:33******** *************** ***********@mic rosoft.com...
1) Expose mybody as property of you user control so parent form can set
reference of mybody into it.


How would I do that?

The problem is that it can't reference it - how do I make it a property in
the user control?

2) Set the UserControl.myb ody = this.mybody in the parent page load.Then
call usercontrol load, it will work.


That would work.

I just wanted to find out how to access properties of the parent page from
a user control. This would obviously have to be looked at closely, but I
am trying to use my user controls on different parent pages that would all
have the same objects, but would be laid out differently.

Thanks,

Tom

Please give feedback of this post.

"tshad" wrote:
I am trying to put together a user control (.ascx).

Can you access an outside control from it?

My control:

login2.ascx
*************** *************** *************** *************** ****
<script runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
if not IsPostBack

myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baselin e">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="Singl eLine" Columns="25"
runat="server" />
<asp:RequiredFi eldValidator
ControlToValida te="UserName"
Text="User Name Required"
runat="server" />
</td>
</tr>
</table>
*************** *************** *************** *************** ****

I get an error on access "mybody" as:

Name 'myBody' is not declared.

My aspx file looks essentially like:
*************** *************** *************** *************** **
<html>
<%@ Register TagPrefix="fts" TagName="Login" Src="login2.asc x" %>
<head>
<title>:: Staffing Workshop ::</title>
</head>

<body id="myBody" runat="server">
<form runat="server">
<fts:Login runat="server"/>
</form>
</body>
</html>
*************** *************** *************** *************** **

If I comment the line:

' myBody.Attribut es.Add("onLoad" ,"document.form s[0].UserName.focus ()")

it works fine.

Is there a way to access this outside body tag from my control?

Thanks,

Tom


May 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1725
by: Tony Hedge | last post by:
Hello, I'd like to reference a control in a user control that is not in the user control. For esample, if I had the following in my .aspx: .... <html> <form ID="frmMain"....> ... <asp:Label ID="lblMessage" ...>...</asp:Label> <uc:MyUserControl ID="ucTest"...></uc:MyUserControl>
3
2795
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different IDs. Thanks Vivek
8
2747
by: Pete Wittig | last post by:
Hello, I am wondering if it is possible to create a networked application with C# that is seen as a windows user. For example, if Bob logged onto windows and then started the application, any access to the network made through the application would be seen as 'C# application user' and not 'Bob'. What I want to accomplish is to create an encrypted folder on a server where files within the folder can be accessed through the application,...
2
3023
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2 or more user controls dynamically by adding to a placeholder defined in page_load. I've included the sample code for how we are accessing one. The user controls are not rocket science - just a few text boxes with public accessor properties. We've...
1
2160
by: Barbara Alderton | last post by:
I have the following scenario: I have a user control that contains a registered menu control. The menu and other information on the user control is specific to the user accessing the site. This user control is used on many pages. In order to create this control, I need to access information in the Active Directory to create both the menu and other info displayed on the control. This access takes some time and I wanted to cache this...
3
1644
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to set the add/edit/delete options visble/invisible on the datagrid depending on the users's role, but found that i cannot access the grid to do this. is the only way of setting it in the page load of the usercontrol itself?
9
1861
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added to the order */ }
2
1958
by: Sin Jeong-hun | last post by:
If I create a button like control, then I simply can draw button-like lines on my User Control's surface by getting its Graphics g. If I draw outside of the control's ClientRectangle (for example, -10,-10,-5,-5), it is simply cut out. But what about if I'm trying to make a dropdown list control in .NET? The dropped down part is outside of the control's ClientRectangle. How can I do such thing? Maybe create a borderless window and display...
4
1685
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub Page_Load(s as Object, e as EventArgs) LoadControl("x.ascx")
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.