How to access a User Control from a Classhttp://forums.asp.net/t/895303.aspx/1?How+to+access+a+User+Control+from+a+ClassFri, 09 Sep 2011 10:54:08 -0400895303963238http://forums.asp.net/p/895303/963238.aspx/1?How+to+access+a+User+Control+from+a+ClassHow to access a User Control from a Class <font face="Verdana" size="2">I have a user control&nbsp; &quot;ItemNotes&quot; in my application and&nbsp;i am trying to access this control type from a class using following code.<br> </font> <p><em><font color="#000000"><font face="Verdana" size="2">Control ctrl = FindControl(&quot;Note1&quot;);<br> if(ctrl is</font></font></em><font face="Verdana" color="#000000" size="2"><em> ItemNotes)<br> {<br> &nbsp; return</em></font><font face="Verdana" color="#000000" size="2"><em> ((ItemNotes)ctrl).Value;<br> }<br> return</em></font><font size="2"><font color="#000000"><font face="Verdana"><em> &quot;&quot;;</em><br> <br> It work fine in ASP.NET 1.1 but doesn't compile in 2.0 and i don't see control class in assigned namespace.&nbsp;By default, this class is in App_Code directory and is a base class for other controls.<br> <br> Is there any way to handle this? </font></font></font></p> 2005-06-20T22:44:08-04:00963441http://forums.asp.net/p/895303/963441.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class <p>A workaround is to make ItemNotes a simple class that is derived from UserControl, and then create a separate user control that derives from ItemNotes and use that in the pages.<br> <br> You can add all the properties/methods that you need to the ItemNotes class (possibly making them virtual or even abstract) and then implement them as needed in the deriving user control class.<br> <br> This gives you<br> <br> public class ItemNotes : UserControl<br> {<br> &nbsp; ...<br> }<br> <br> partial class ItemNotesControl : ItemNotes<br> {<br> &nbsp; ...<br> }<br> <br> <br> <br> </p> 2005-06-21T03:05:06-04:00964147http://forums.asp.net/p/895303/964147.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class You should also just be able to add a Page reference to that user control<br> &lt;%@Reference VirtualPath=&quot;ItemNotes.ascx&quot; %&gt; 2005-06-21T16:47:09-04:00964568http://forums.asp.net/p/895303/964568.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class Thanks DMV,&nbsp;&nbsp; I created a virtual function in the&nbsp;old class so now i am handling ItemNotes in derived controls. Works fine. 2005-06-21T22:08:52-04:00964605http://forums.asp.net/p/895303/964605.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class <p>I can add a reference to a page or another control. But i was trying to access it from a base class file derived from UserControl.&nbsp; This&nbsp;class file is in App_Code directory and working as a&nbsp;base class for other user controls.&nbsp;&nbsp;there were no problems in derived controls.&nbsp;I&nbsp; cannot access any page or User control&nbsp;in App_Code folder classes.&nbsp;It doesn't compile.&nbsp;<br> <br> I found another solution as i replied to DMW.<br> <br> thanks<br> Saurabh</p> 2005-06-21T22:40:28-04:00968165http://forums.asp.net/p/895303/968165.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class Files in&nbsp;&nbsp;App_code&nbsp; cannot refer classes out side. Whidbey conversion wizad solves this problem by creating an abstract base class in app_code.<br> This abstract base class is the base class for the classes out side App_code, and code in side app_code can still use it.<br> <br> Eg:<br> &nbsp;<br> Myppage.aspx.cs<br> partial class MyPage : Page<br> {<br> public int foo()<br> {<br> &nbsp; return 1;<br> }<br> }<br> <br> After conversion<br> <br> partial class Migrated_MyPage : MyPage<br> {<br> &nbsp; override public foo()<br> {<br> &nbsp;&nbsp; return 1;<br> }<br> }<br> <br> in app_code&nbsp; new file generated<br> Stub_Mypage_aspx_cs.cs<br> <br> abstarct class MyPage : Page<br> {<br> &nbsp;abstract public int foo() ;<br> }<br> <br> Now code in App_code can refer MyPage and can use public methods if code has access to Migrated_MyPage instance. 2005-06-24T17:36:26-04:004590057http://forums.asp.net/p/895303/4590057.aspx/1?Re+How+to+access+a+User+Control+from+a+ClassRe: How to access a User Control from a Class <p>&nbsp;in&nbsp;&nbsp;App_code&nbsp;&nbsp; i have a commompage.vb class file and in main solution i have a user control(.ascx).i need to access this user contol into my commonpage.vb class..plz help me out this issue.give a example...</p> 2011-09-09T10:54:08-04:00