Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > User control accessing outside control

Reply
Thread Tools

User control accessing outside control

 
 
tshad
Guest
Posts: n/a
 
      05-19-2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWx0YWYgQWwtQW1pbiBOYWp3YW5p?=
Guest
Posts: n/a
 
      05-19-2006
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
>
>
>

 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      05-19-2006
"Altaf Al-Amin Najwani" <> wrote in message
news:33588B4F-849E-4B91-8470-...
> 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
>>
>>
>>



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      05-19-2006
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" <> wrote in message
news:...
> "Altaf Al-Amin Najwani" <> wrote in message
> news:33588B4F-849E-4B91-8470-...
>> 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
>>>
>>>
>>>

>
>



 
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
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
User Controls accessing outside objects tshad ASP .Net 4 08-03-2006 11:30 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
Accessing Datagrid properties within a user control from the outside Craig G ASP .Net 3 11-30-2004 02:51 PM



Advertisments