473,288 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

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(sender as Object, e as EventArgs)
if not IsPostBack
myBody.Attributes.Add("onLoad","document.forms[0].UserName.focus()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baseline">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="SingleLine" Columns="25"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="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.ascx" %>
<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.Attributes.Add("onLoad","document.forms[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 1752
1) Expose mybody as property of you user control so parent form can set
reference of mybody into it.

2) Set the UserControl.mybody = 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(sender as Object, e as EventArgs)
if not IsPostBack
myBody.Attributes.Add("onLoad","document.forms[0].UserName.focus()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baseline">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="SingleLine" Columns="25"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="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.ascx" %>
<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.Attributes.Add("onLoad","document.forms[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**********@gmail.com> wrote in message
news:33**********************************@microsof t.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.mybody = 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(sender as Object, e as EventArgs)
if not IsPostBack
myBody.Attributes.Add("onLoad","document.forms[0].UserName.focus()")
UserName.Text = "This is a test"
else
end if
End Sub

</script>
<table border="0" width="106%" >
<tr valign="baseline">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="SingleLine" Columns="25"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="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.ascx" %>
<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.Attributes.Add("onLoad","document.forms[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**********@ftsolutions.com> wrote in message
news:en**************@TK2MSFTNGP04.phx.gbl...
"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:33**********************************@microsof t.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.mybody = 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(sender as Object, e as EventArgs)
if not IsPostBack

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

</script>
<table border="0" width="106%" >
<tr valign="baseline">
<td width="99" align="right" valign="middle" nowrap >User Name :</td>
<td width="500" align="left" >
<asp:textbox id="UserName" TextMode="SingleLine" Columns="25"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="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.ascx" %>
<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.Attributes.Add("onLoad","document.forms[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
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...
3
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...
8
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...
2
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...
1
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. ...
3
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...
9
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...
2
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,...
4
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.