How to create an instance of user control in a class(simple) file notin Page class file?

C

chandan

Hi,
How to create an instance of user control in a class(simple) file not
in Page class file? As I tried I can do it in page class file but not
in simple class file.
Let me know the solution!!

Thanks,
Chandan kumar
 
J

Jayakrishnan

chandan said:
Hi,
How to create an instance of user control in a class(simple) file not
in Page class file? As I tried I can do it in page class file but not
in simple class file.
Let me know the solution!!

Thanks,
Chandan kumar

Add the following tags in web.config

<pages>
<controls>
<add tagPrefix="Page" tagName="ActionPane" src="~/UserControl/Header.ascx"/>
</controls>
</pages>

Add the following method in class file

Public Class Sample
Public Function GetControl() As Control
Dim objHeader As Control
Dim objLoad As New System.Web.UI.UserControl

objHeader = objLoad.LoadControl("~/Controls/Header.ascx")
Return objHeader
End Function
End Class

If you need to access in page add the following code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim obj As New Sample
Panel1.Controls.Add(obj.GetControl())
End Sub

Jayakrishnan V
Technology Group
 
C

chandan

Add the following tags in web.config

<pages>
<controls>
<add tagPrefix="Page" tagName="ActionPane" src="~/UserControl/Header.ascx"/>
</controls>
</pages>

Add the following method in class file

Public Class Sample
Public Function GetControl() As Control
Dim objHeader As Control
Dim objLoad As New System.Web.UI.UserControl

objHeader = objLoad.LoadControl("~/Controls/Header.ascx")
Return objHeader
End Function
End Class

If you need to access in page add the following code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim obj As New Sample
Panel1.Controls.Add(obj.GetControl())
End Sub

Jayakrishnan V
Technology Group

Thanks Jayakrishnan...

But my actual proble is:
How to create object of a class which is outside of App_Code folder in
Asp.net 2.0 using C#.??

Let me know if you have solution???
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top