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.