|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
User control accessing outside controlCan 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 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. Show quoteHide quote "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 > > > "Altaf Al-Amin Najwani" <altaf.ala***@gmail.com> wrote in message How would I do that?news:33588B4F-849E-4B91-8470-DA921CDC8D7E@microsoft.com... > 1) Expose mybody as property of you user control so parent form can set > reference of mybody into it. The problem is that it can't reference it - how do I make it a property in the user control? > That would work.> 2) Set the UserControl.mybody = this.mybody in the parent page load.Then > call usercontrol load, it will 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 Show quoteHide quote > > 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 >> >> >> 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 Show quoteHide quote "tshad" <tscheider***@ftsolutions.com> wrote in message news:enCwge1eGHA.2076@TK2MSFTNGP04.phx.gbl... > "Altaf Al-Amin Najwani" <altaf.ala***@gmail.com> wrote in message > news:33588B4F-849E-4B91-8470-DA921CDC8D7E@microsoft.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 >>> >>> >>> > >
Other interesting topics
SDK VS RUNTIME LIBRARY
Populate Dropdown from SQL Server Second Super Simple Question (Which I cant get!) Line break in GridView Header Text Postback,Master page,User control problem Datasource doesn't generate data SqlDataSource GridView: Calculated Field Hot to handle "Directory not found" from ASP.NET? Need Control type |
|||||||||||||||||||||||