473,399 Members | 3,302 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,399 software developers and data experts.

loading ascx control dynamically in placeholder

Hi

I am trying to load my user control in a placeholder,

i get an error: c:\inetpub\wwwroot\testinline\WebForm2.aspx.vb(26) : Type
'WebUserControl6' is not defined?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx"), WebUserControl6)

PlaceHolder1.Controls.Add(uc)

End Sub

ascx control:

<%@ Reference Control = "WebUserControl6.ascx" %>
hello

thanks

B.


Dec 11 '06 #1
3 9635
thanks

what if the ascx control has no code behind as in my case? So the compiler
does not recognize type webusercontrol6? How do I do that?

"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Hi,
Is the code which you have written for UserControl in the same project or
some other project?
If it is in different project then i think you need to add reference to it
i would suggest you to include the code which you writen for usercontrol
in
same project and see if it is working or not
also in following line of code
Dim uc As WebUserControl6 =
>DirectCast(Me.LoadControl("WebUserControl6.ascx") , WebUserControl6)

WebUserControl6 should be the name of UserControl Class.

Thanks and Regards,
manish bafna

"Bert" wrote:
>Hi

I am trying to load my user control in a placeholder,

i get an error: c:\inetpub\wwwroot\testinline\WebForm2.aspx.vb(26) : Type
'WebUserControl6' is not defined?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx") , WebUserControl6)

PlaceHolder1.Controls.Add(uc)

End Sub

ascx control:

<%@ Reference Control = "WebUserControl6.ascx" %>
hello

thanks

B.



Dec 11 '06 #2
Hi,
I was wondering what purpose the UserControl will serve if it does not have
code-behind.You will be not able to set properties/raise events etc.Can you
describe in detail what your usercontrol is trying to do.

Thanks and Regards,
manish bafna

"Bert" wrote:
thanks

what if the ascx control has no code behind as in my case? So the compiler
does not recognize type webusercontrol6? How do I do that?

"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Hi,
Is the code which you have written for UserControl in the same project or
some other project?
If it is in different project then i think you need to add reference to it
i would suggest you to include the code which you writen for usercontrol
in
same project and see if it is working or not
also in following line of code
Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx"), WebUserControl6)
WebUserControl6 should be the name of UserControl Class.

Thanks and Regards,
manish bafna

"Bert" wrote:
Hi

I am trying to load my user control in a placeholder,

i get an error: c:\inetpub\wwwroot\testinline\WebForm2.aspx.vb(26) : Type
'WebUserControl6' is not defined?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx"), WebUserControl6)

PlaceHolder1.Controls.Add(uc)

End Sub

ascx control:

<%@ Reference Control = "WebUserControl6.ascx" %>
hello

thanks

B.




Dec 11 '06 #3
re:
I was wondering what purpose the UserControl will serve if it does not have
code-behind.You will be not able to set properties/raise events etc.
Why not ?

I'd find it really odd if this code didn't work, yet it doesn't use code-behind.

DisplayNumber.ascx :
-----------------------------

<%@ Control Language="VB" ClassName="Spinner" %>
<script runat="server">
Private m_minValue As Integer = 0
Private m_maxValue As Integer = 100
Private m_currentNumber As Integer = 0
Public Property MinValue() As Integer
Get
Return m_minValue
End Get
Set(ByVal value As Integer)
If value >= Me.MaxValue Then
Throw New Exception _
("MinValue must be less than MaxValue.")
Else
m_minValue = value
End If
End Set
End Property

Public Property MaxValue() As Integer
Get
Return m_maxValue
End Get
Set(ByVal value As Integer)
If value <= Me.MinValue Then
Throw New Exception _
("MaxValue must be greater than MinValue.")
Else
m_maxValue = value
End If
End Set
End Property

Public ReadOnly Property CurrentNumber() As Integer
Get
Return m_currentNumber
End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
If IsPostBack Then
m_currentNumber = CInt(ViewState("currentNumber"))
Else
m_currentNumber = Me.MinValue
End If
DisplayNumber()
End Sub

Protected Sub DisplayNumber()
textNumber.Text = Me.CurrentNumber.ToString()
ViewState("currentNumber") = Me.CurrentNumber.ToString()
End Sub

Protected Sub buttonUp_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If m_currentNumber = Me.MaxValue Then
m_currentNumber = Me.MinValue
Else
m_currentNumber += 1
End If
DisplayNumber()
End Sub

Protected Sub buttonDown_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If m_currentNumber = Me.MinValue Then
m_currentNumber = Me.MaxValue
Else
m_currentNumber -= 1
End If
DisplayNumber()
End Sub
</script>
<asp:TextBox ID="textNumber" runat="server"
ReadOnly="True" Width="32px" Enabled="False" />
<asp:Button Font-Bold="True" ID="buttonUp" runat="server"
Text="^" OnClick="buttonUp_Click" />
<asp:Button Font-Bold="True" ID="buttonDown" runat="server"
Text="v" OnClick="buttonDown_Click" />
--------------------------------------------------------------------

Bottom line : you are mistaken.
You can do inline amything that you can do in code-behind.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:32**********************************@microsof t.com...
Hi,
I was wondering what purpose the UserControl will serve if it does not have
code-behind.You will be not able to set properties/raise events etc.Can you
describe in detail what your usercontrol is trying to do.

Thanks and Regards,
manish bafna

"Bert" wrote:
>thanks

what if the ascx control has no code behind as in my case? So the compiler
does not recognize type webusercontrol6? How do I do that?

"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:61**********************************@microso ft.com...
Hi,
Is the code which you have written for UserControl in the same project or
some other project?
If it is in different project then i think you need to add reference to it
i would suggest you to include the code which you writen for usercontrol
in
same project and see if it is working or not
also in following line of code
Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx") , WebUserControl6)

WebUserControl6 should be the name of UserControl Class.

Thanks and Regards,
manish bafna

"Bert" wrote:

Hi

I am trying to load my user control in a placeholder,

i get an error: c:\inetpub\wwwroot\testinline\WebForm2.aspx.vb(26) : Type
'WebUserControl6' is not defined?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim uc As WebUserControl6 =
DirectCast(Me.LoadControl("WebUserControl6.ascx") , WebUserControl6)

PlaceHolder1.Controls.Add(uc)

End Sub

ascx control:

<%@ Reference Control = "WebUserControl6.ascx" %>
hello

thanks

B.





Dec 12 '06 #4

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

Similar topics

2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
1
by: John Cosmas | last post by:
I've got a page which loads up a different user control into a placeholder control every time a button is clicked on the parent page. I use a statement like...
7
by: Tim | last post by:
I am trying to load both server and user controls into placeholder controls on a aspx template page at runtime. These values would be strings that are returned from a database query. I know I can...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
5
by: footballhead | last post by:
I have a site that has MANY different clothing categories. I have a page set up for displaying the products (productsearch.aspx) when a user clicks one of the category links on the navigation menu....
2
by: Dave A | last post by:
I just don't get this... If I need to dynamically load controls into a web page I simply need to go PlaceHolder1.Controls.Add(new Button()); or similar. However when I need to dynamically...
1
by: Wouter | last post by:
Hi, I hope somebody can give me a pointer to solve the following problem. I want to dynamically load a web usercontrol (ascx) into a content control of a content page which references a master...
3
by: Wouter | last post by:
Hi All, I am loading a web user control (.NET 2.0) into a placeholder on a content page ( plus the use of a master page). The controls is a list of companie, one you select a company for...
2
by: Lloyd Sheen | last post by:
Ok I have created a small testbed site for testing and I am have a problem with the terms Usercontrol, Webcontrol, etc. What I need to do in the long run is have a page using AJAX and having...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.