By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
chandan wrote:
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
Nov 28 '07 #2

P: n/a
On Nov 28, 1:25 pm, Jayakrishnan <jayakrish...@iinterchange.com>
wrote:
chandan wrote:
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
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???
Dec 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.