473,385 Members | 1,888 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,385 software developers and data experts.

how to load an ascx file in class.vb ?

I need to import an *;ascx, as an object, in my class, that is in
myclass.vb. How can i do ? i saw the method LoadControl but i can't use it,
or maybe i did wrong, if could help me it would be very nice :)

Bisous de France et merci d'avance.
Nov 17 '05 #1
6 6497
LoadControl is what you want. Example in VB:

Dim myControl as Control = LoadControl("MyControl.ascx")
Me.Controls.Add(myControl)

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
I need to import an *;ascx, as an object, in my class, that is in
myclass.vb. How can i do ? i saw the method LoadControl but i can't use it, or maybe i did wrong, if could help me it would be very nice :)

Bisous de France et merci d'avance.

Nov 17 '05 #2
Thank you for your response but when i've already tried
LoadControl("myfile.ascx") and an error shows up saying that LoadControl
hasn't been declared.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
uP**************@tk2msftngp13.phx.gbl...
LoadControl is what you want. Example in VB:

Dim myControl as Control = LoadControl("MyControl.ascx")
Me.Controls.Add(myControl)

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
I need to import an *;ascx, as an object, in my class, that is in
myclass.vb. How can i do ? i saw the method LoadControl but i can't use

it,
or maybe i did wrong, if could help me it would be very nice :)

Bisous de France et merci d'avance.


Nov 17 '05 #3
This is a method of the Page calss, so it is certainly there.

How and where are you trying to do this? Show your code.

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
Thank you for your response but when i've already tried
LoadControl("myfile.ascx") and an error shows up saying that LoadControl
hasn't been declared.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
uP**************@tk2msftngp13.phx.gbl...
LoadControl is what you want. Example in VB:

Dim myControl as Control = LoadControl("MyControl.ascx")
Me.Controls.Add(myControl)

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
I need to import an *;ascx, as an object, in my class, that is in
myclass.vb. How can i do ? i saw the method LoadControl but i can't
use it,
or maybe i did wrong, if could help me it would be very nice :)

Bisous de France et merci d'avance.



Nov 17 '05 #4
I'm trying to do this in a file of classes named MesClasses.vb and here is a
simple version of the code :

-----------------------------MesClasses.vb ---------------------------------
---------

Public Class MaFenetre : inherits WebControl
Private MyTable As New HtmlTable

Public Sub New()
Dim MyRow As New HtmlTableRow
Dim MyCell As New HtmlTableCell

MyRow.Cells.Add(MyCell)
MyTable.Rows.Add(MyRow)

End Sub

Public Property AscxFile() As String
Get
Return AscxFile
End Get
Set (ByVal Value As String)
AscxFile = Value
AddAscx(AscxFile)
End Set
End Property

Private Sub AddAscx(ByVal PathAscx As String)
Dim MyObjectAscx As Control = LoadControl(PathAscx)
MyTable.Rows(0).Cells(0).Controls.Add(MyObjectAscx )
End Sub

End Class

--------------------------

----------------------
index.aspx -------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim InnerPage As New MaFenetre
InnerPage.AscxFile("myfile.ascx")
End Sub
---------------------------
Thanks you again for your response so quick :) and excuse my english :)

regards.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
#w**************@TK2MSFTNGP09.phx.gbl...
This is a method of the Page calss, so it is certainly there.

How and where are you trying to do this? Show your code.

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
Thank you for your response but when i've already tried
LoadControl("myfile.ascx") and an error shows up saying that LoadControl
hasn't been declared.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
uP**************@tk2msftngp13.phx.gbl...
LoadControl is what you want. Example in VB:

Dim myControl as Control = LoadControl("MyControl.ascx")
Me.Controls.Add(myControl)

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
> I need to import an *;ascx, as an object, in my class, that is in
> myclass.vb. How can i do ? i saw the method LoadControl but i can't use it,
> or maybe i did wrong, if could help me it would be very nice :)
>
> Bisous de France et merci d'avance.
>
>



Nov 17 '05 #5
oh thank you again :-D I'm a newbie in .net programming and you help me so
much :)

i'm ashamed to say that i still have a problem... Me.Page.LoadControl works
fine but i got an error when i run the page, saying that an object reference
is not defined at the "instance" of an object (in french : "La référence
d'un objet n'est pas définie à l'instance d'un objet")... Again excuse my
poor english :-\ And i got this error on this line :

Me.Page.LoadControl("demo.ascx")

Maybe it's because my file of classes MesClasses.vb is located in an other
project so the path is not correct ? The tree of y solution is like :

Solution
--- Web Project
------ index.aspx
--- Classes Project
------ MesClasses.vb

I hope you understood me... Merci encore.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
OS**************@TK2MSFTNGP09.phx.gbl...
If you looked up LoadControl, you would have seen that this is a property of the Page class. However, you are not inheriting from the Page class - so
you cannot inherit this method.

You are inheriting from WebControl - so you need to find a way to get to the Page object on which your WebControl will live.

Conveniently, WebControl class has a Page property. And because you are
inheriting from WebControl, you are inheriting this property as well.

So you would call it:

Me.Page.LoadControl("MyControl.ascx")

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm trying to do this in a file of classes named MesClasses.vb and here is
a
simple version of the code :


-----------------------------MesClasses.vb -------------------------------
--
---------

Public Class MaFenetre : inherits WebControl
Private MyTable As New HtmlTable

Public Sub New()
Dim MyRow As New HtmlTableRow
Dim MyCell As New HtmlTableCell

MyRow.Cells.Add(MyCell)
MyTable.Rows.Add(MyRow)

End Sub

Public Property AscxFile() As String
Get
Return AscxFile
End Get
Set (ByVal Value As String)
AscxFile = Value
AddAscx(AscxFile)
End Set
End Property

Private Sub AddAscx(ByVal PathAscx As String)
Dim MyObjectAscx As Control = LoadControl(PathAscx)
MyTable.Rows(0).Cells(0).Controls.Add(MyObjectAscx )
End Sub

End Class

--------------------------

----------------------
index.aspx -------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim InnerPage As New MaFenetre
InnerPage.AscxFile("myfile.ascx")
End Sub
---------------------------
Thanks you again for your response so quick :) and excuse my english :)

regards.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
#w**************@TK2MSFTNGP09.phx.gbl...
This is a method of the Page calss, so it is certainly there.

How and where are you trying to do this? Show your code.

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
> Thank you for your response but when i've already tried
> LoadControl("myfile.ascx") and an error shows up saying that

LoadControl > hasn't been declared.
>
> "Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news: > uP**************@tk2msftngp13.phx.gbl...
> > LoadControl is what you want. Example in VB:
> >
> > Dim myControl as Control = LoadControl("MyControl.ascx")
> > Me.Controls.Add(myControl)
> >
> > "Quentin" <Qu****************@wanadoo.Fr> wrote in message
> > news:eV**************@TK2MSFTNGP09.phx.gbl...
> > > I need to import an *;ascx, as an object, in my class, that is in > > > myclass.vb. How can i do ? i saw the method LoadControl but i can't use
> > it,
> > > or maybe i did wrong, if could help me it would be very nice :)
> > >
> > > Bisous de France et merci d'avance.
> > >
> > >
> >
> >
>
>



Nov 17 '05 #6
Quentin,
Try using the ~ character in your path, to specify the root of the
current webspace. In order words, try doing this:
Me.Page.LoadControl("~/demo.ascx")

That should load a user control that is located in the root folder of
your web application named demo.ascx. I haven't tried a configuration
exactly like yours, but I think this should work.

Ryan Gregg

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
oh thank you again :-D I'm a newbie in .net programming and you help me so
much :)

i'm ashamed to say that i still have a problem... Me.Page.LoadControl works fine but i got an error when i run the page, saying that an object reference is not defined at the "instance" of an object (in french : "La référence
d'un objet n'est pas définie à l'instance d'un objet")... Again excuse my
poor english :-\ And i got this error on this line :

Me.Page.LoadControl("demo.ascx")

Maybe it's because my file of classes MesClasses.vb is located in an other
project so the path is not correct ? The tree of y solution is like :

Solution
--- Web Project
------ index.aspx
--- Classes Project
------ MesClasses.vb

I hope you understood me... Merci encore.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news:
OS**************@TK2MSFTNGP09.phx.gbl...
If you looked up LoadControl, you would have seen that this is a property
of
the Page class. However, you are not inheriting from the Page class - so you cannot inherit this method.

You are inheriting from WebControl - so you need to find a way to get to the
Page object on which your WebControl will live.

Conveniently, WebControl class has a Page property. And because you are
inheriting from WebControl, you are inheriting this property as well.

So you would call it:

Me.Page.LoadControl("MyControl.ascx")

"Quentin" <Qu****************@wanadoo.Fr> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm trying to do this in a file of classes named MesClasses.vb and here is
a
simple version of the code :


-----------------------------MesClasses.vb -------------------------------
--
---------

Public Class MaFenetre : inherits WebControl
Private MyTable As New HtmlTable

Public Sub New()
Dim MyRow As New HtmlTableRow
Dim MyCell As New HtmlTableCell

MyRow.Cells.Add(MyCell)
MyTable.Rows.Add(MyRow)

End Sub

Public Property AscxFile() As String
Get
Return AscxFile
End Get
Set (ByVal Value As String)
AscxFile = Value
AddAscx(AscxFile)
End Set
End Property

Private Sub AddAscx(ByVal PathAscx As String)
Dim MyObjectAscx As Control = LoadControl(PathAscx)
MyTable.Rows(0).Cells(0).Controls.Add(MyObjectAscx )
End Sub

End Class

--------------------------

----------------------
index.aspx -------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim InnerPage As New MaFenetre
InnerPage.AscxFile("myfile.ascx")
End Sub
---------------------------
Thanks you again for your response so quick :) and excuse my english

:)
regards.

"Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de news: #w**************@TK2MSFTNGP09.phx.gbl...
> This is a method of the Page calss, so it is certainly there.
>
> How and where are you trying to do this? Show your code.
>
> "Quentin" <Qu****************@wanadoo.Fr> wrote in message
> news:OR**************@TK2MSFTNGP11.phx.gbl...
> > Thank you for your response but when i've already tried
> > LoadControl("myfile.ascx") and an error shows up saying that

LoadControl
> > hasn't been declared.
> >
> > "Marina" <zl*******@nospam.hotmail.com> a écrit dans le message de

news:
> > uP**************@tk2msftngp13.phx.gbl...
> > > LoadControl is what you want. Example in VB:
> > >
> > > Dim myControl as Control = LoadControl("MyControl.ascx")
> > > Me.Controls.Add(myControl)
> > >
> > > "Quentin" <Qu****************@wanadoo.Fr> wrote in message
> > > news:eV**************@TK2MSFTNGP09.phx.gbl...
> > > > I need to import an *;ascx, as an object, in my class, that is

in > > > > myclass.vb. How can i do ? i saw the method LoadControl but i

can't
> use
> > > it,
> > > > or maybe i did wrong, if could help me it would be very nice :) > > > >
> > > > Bisous de France et merci d'avance.
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Quentin | last post by:
hey there, ok i made a class, that inherits webcontrol, and i add an htmltable to it. I was wondering how to declare an ascx file as an object in my class, like that i could change the content...
4
by: Rob Meade | last post by:
Hi all, I have just put together our organisations 'template' for our web applications and have created 7 .ascx files which when dropped into my template file work perfectly...however, I have a...
2
by: michael | last post by:
is it possible to include a ascx file in another ascx file in the codebehind? for example something like <asp:panel pnl src="test.ascx"></asp:panel i want to control in the codebehind which ascx...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
0
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a...
1
by: ddelaney | last post by:
I've seen this posted before in many places, but have yet to find a real fix. I have a web application on dev server right now, and randomly, hours or days, it returns the expception posted below. ...
5
by: google | last post by:
Hi, I'm using loadControl to load an ascx into a variable. This works ok but I'm having to load the control into an Object variable e.g. Dim aWidget As Object =...
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.