I created my first user control. Just two boxes with a colon between them to represent time. Something does not seem to be right though and I don't know what I'm doing wrong. When I drag the control onto a web page, it doesn't render correctly and instead
looks like this:
I can create the control by typing in the code mysel and, it will render when the page loads but I am not able to access its properties (i.e. I can not manipulate x.hour or x.minute) I reapplied SP1 to make sure that nothing had become corrupt but
the problem persists. Note also that I created a new "test" control just to make sure that this one had not become corrupt but it too has the same problems. Below are my ascx and aspx files. I've purposely made this as basic as possible to avoid any other
extraneous problems. I'm very frustrated and don't know why this isn't working.
ASCX
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TimeBox.ascx.vb" Inherits="Time_Entry_System.TimeBox" %>
<script runat="server">
Public Property Hour() As Integer
Set(value As Integer)
txtHour.Text = value.ToString
End Set
Get
Hour = CInt(txtHour.Text)
End Get
End Property
Public Property Minute() As Integer
Set(value As Integer)
txtMinute.Text = value.ToString
End Set
Get
Minute = CInt(txtMinute.Text)
End Get
End Property
</script>
<asp:TextBox ID="txtHour" runat="server" Width="25px"></asp:TextBox>
<b>:</b>
<asp:TextBox ID="txtMinute" runat="server" Width="25px"></asp:TextBox>
ASPX (note that the .vb page has "Imports Time_Entry_System.TimeBox" statement)
I used this and have followed it completely. I think that the above would not be how I'm trying to build my solution. Am I using the properties I built correctly?
It doesn't generate any errors and it does render properly on the page when I set the initial properties. But if I try and access its properties in code, then it will generate an error.
I will try and find someone to test for me as I'm a solo shop.
In my mind,I've tested your program and everything goes with me just fine!My codes are above:
Just one reminder:please make sure that your Get property should return a value……
【UserControl】
Public Class WebUserControl1
Inherits System.Web.UI.UserControl
Public Property Hours() As Integer
Set(value As Integer)
txtHour.Text = value.ToString
End Set
Get
Return txtHour.Text
End Get
End Property
Public Property Minutes() As Integer
Set(value As Integer)
txtMinute.Text = value.ToString
End Set
Get
Return txtMinute.Text
End Get
End Property
End Class
JonnyBravoII
Member
43 Points
74 Posts
Can't access public properties in code
May 14, 2012 12:29 PM|LINK
I created my first user control. Just two boxes with a colon between them to represent time. Something does not seem to be right though and I don't know what I'm doing wrong. When I drag the control onto a web page, it doesn't render correctly and instead looks like this:
<a href="~/Controls/TimeBox.ascx">~/Controls/TimeBox.ascx</a>
I can create the control by typing in the code mysel and, it will render when the page loads but I am not able to access its properties (i.e. I can not manipulate x.hour or x.minute) I reapplied SP1 to make sure that nothing had become corrupt but the problem persists. Note also that I created a new "test" control just to make sure that this one had not become corrupt but it too has the same problems. Below are my ascx and aspx files. I've purposely made this as basic as possible to avoid any other extraneous problems. I'm very frustrated and don't know why this isn't working.
ASCX
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TimeBox.ascx.vb" Inherits="Time_Entry_System.TimeBox" %>
<script runat="server">
Public Property Hour() As Integer
Set(value As Integer)
txtHour.Text = value.ToString
End Set
Get
Hour = CInt(txtHour.Text)
End Get
End Property
Public Property Minute() As Integer
Set(value As Integer)
txtMinute.Text = value.ToString
End Set
Get
Minute = CInt(txtMinute.Text)
End Get
End Property
</script>
<asp:TextBox ID="txtHour" runat="server" Width="25px"></asp:TextBox>
<b>:</b>
<asp:TextBox ID="txtMinute" runat="server" Width="25px"></asp:TextBox>
ASPX (note that the .vb page has "Imports Time_Entry_System.TimeBox" statement)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm3.aspx.vb" Inherits="Time_Entry_System.WebForm3" %>
<%@ Register src="~/Controls/TimeBox.ascx" tagname="TimeBox" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:TimeBox ID="testcontrol" runat="server" Hour="4" and Minute="0" />
</form>
</body>
</html>
Kishore Bari...
Participant
879 Points
182 Posts
Re: Can't access public properties in code
May 14, 2012 12:43 PM|LINK
Hi,
Please follow this link, I think your problem will be solved.
http://msdn.microsoft.com/en-us/library/12yydcke.aspx
Insync Tech-Fin Solutions Ltd.
(India)
JonnyBravoII
Member
43 Points
74 Posts
Re: Can't access public properties in code
May 14, 2012 12:59 PM|LINK
I used this and have followed it completely. I think that the above would not be how I'm trying to build my solution. Am I using the properties I built correctly?
http://msdn.microsoft.com/en-us/library/y6wb1a0e.aspx
Kishore Bari...
Participant
879 Points
182 Posts
Re: Can't access public properties in code
May 14, 2012 01:24 PM|LINK
Ok, your code does not have any problem.
Does it generating any error during dev or production.
Please try to test once in another system.
Kishore
Insync Tech-Fin Solutions Ltd.
(India)
JonnyBravoII
Member
43 Points
74 Posts
Re: Can't access public properties in code
May 14, 2012 02:50 PM|LINK
It doesn't generate any errors and it does render properly on the page when I set the initial properties. But if I try and access its properties in code, then it will generate an error.
I will try and find someone to test for me as I'm a solo shop.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Can't access public properties in code
May 16, 2012 01:31 AM|LINK
Hello:)
In my mind,I've tested your program and everything goes with me just fine!My codes are above:
Just one reminder:please make sure that your Get property should return a value……
【UserControl】
Public Class WebUserControl1 Inherits System.Web.UI.UserControl Public Property Hours() As Integer Set(value As Integer) txtHour.Text = value.ToString End Set Get Return txtHour.Text End Get End Property Public Property Minutes() As Integer Set(value As Integer) txtMinute.Text = value.ToString End Set Get Return txtMinute.Text End Get End Property End Class【WebPage】
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="VBWebForm.WebForm1" %> <%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <uc1:WebUserControl1 ID="WebUserControl11" runat="server" Hours="4" Minutes="0" /> </form> </body> </html>