User control accessing outside control

T

tshad

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
 
G

Guest

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.
 
T

tshad

Altaf Al-Amin Najwani said:
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 said:
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
 
T

tshad

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 said:
Altaf Al-Amin Najwani said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top