473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
2 3917
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Justin Sane | last post by:
I have bought a book to learn C++, I bought Jesse Liberty's thick book, and so far I haven't seen how I can create simple applications for Windows with buttons, checkboxes, text areas, etc......
6
by: Robert Werner | last post by:
I want to write one general purpose set of code that will handle the population (where required) of all controls on a form. Though I'm new to C# my instinct is to somehow hook into the Load event...
3
by: CroDude | last post by:
Hi all! I've made a button from scratch derived from a Control class. The main reason why Control and not Button class is used for inheritance is that when deriving from a control class it's...
1
by: chavdar | last post by:
I need to inherit web user control page, how can I do this? Thanks, Chavdar
0
by: conckrish | last post by:
Hi all, Can anyone tell me how to add Click event for dynamically created User control page ?? I have a user control page in datagrid cell. when i click this user control page it ll redirect...
6
by: conckrish | last post by:
Hi all Can anyone tell me how to add a click event for a user control page dynamically??? Thanx Krish.
1
by: Christian Perthen | last post by:
Hi, I have a sub in the codebehind page of a user control file that writes html. How do I get the sub triggered and output the html in the content page? See my approach below. Partial Class...
10
by: Wing Siu | last post by:
Dear All I would like to develop a generic class sorting function. Currently, when I need sort a collection of user class, for example: Person, Exhibition, Country I need implement a comparer...
4
by: lakul | last post by:
Hi everyone i m new to this topic. i would like to know that, how we can create simple wave file of 8bit mono ? can anybody guide me to learn out this wonderfull feature of C/C++?
1
by: kkshansid | last post by:
to promote urdu language i want to create simple article like shayari etc (in urdu language )submitter where a user can submit article in urdu it get saved in data base in urdu and then get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.