473,320 Members | 2,048 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,320 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 1753
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...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.